Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nsqd: do not print EOF when closing cleanly #560

Merged
merged 1 commit into from
Mar 23, 2015
Merged

nsqd: do not print EOF when closing cleanly #560

merged 1 commit into from
Mar 23, 2015

Conversation

twmb
Copy link
Contributor

@twmb twmb commented Mar 23, 2015

When nsqd shuts down, protocol_v2 responds to CLS with CLOSE_WAIT and then the
IOLoop waits for another command with ReadSlice on the buffered client
connection. ReadSlice returns EOF because the client closes the connection;
this error is returned from IOLoop to the tcp handler and printed.

Because the presence of EOF is expected when the client is in stateClosing, the
error should be ignored.

@@ -113,6 +113,9 @@ func (p *protocolV2) IOLoop(conn net.Conn) error {
if client.Channel != nil {
client.Channel.RemoveClient(client.ID)
}
if err == io.EOF && atomic.LoadInt32(&client.State) == stateClosing {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly what I had in mind, but I'm not sure io.EOF is the only error possible in this state - if we're in stateClosing I think all errors should be ignored, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring all errors would mask if a connection issued CLS followed by FIN or other messages (which error with cannot XYZ in current state). Also, it looks like PUB/MPUB can still be issued while closing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we move this code into readLoop it can more explicitly ignore all errors related to the socket after a CLS exchange.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, changed.

@mreiferson
Copy link
Member

fixes #521

@mreiferson mreiferson changed the title nsqd: do not print EOF when closing cleanly. nsqd: do not print EOF when closing cleanly Mar 23, 2015
@@ -62,7 +62,11 @@ func (p *protocolV2) IOLoop(conn net.Conn) error {
// ie. the returned slice is only valid until the next call to it
line, err = client.Reader.ReadSlice('\n')
if err != nil {
err = fmt.Errorf("failed to read command - %s", err)
if err == io.EOF && atomic.LoadInt32(&client.State) == stateClosing {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, so now we can just do this for any error, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure that ErrBufFull should be ignored, but since we're closing I guess it really doesn't matter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I think the idea is to clean up logging here - we've already done the CLS exchange at this point and I think any read-based error is just noise.

When nsqd shuts down, protocol_v2 responds to CLS with CLOSE_WAIT and then the
IOLoop waits for another command with ReadSlice on the buffered client
connection. ReadSlice could return an error because the client closes the
connection or if the read buffer is full.  This error is returned from IOLoop
to the tcp handler and printed.

Because we are shutting down, we do not care about the error.
@mreiferson
Copy link
Member

👍

mreiferson added a commit that referenced this pull request Mar 23, 2015
nsqd: do not print EOF when closing cleanly
@mreiferson mreiferson merged commit 48bb782 into nsqio:master Mar 23, 2015
@mreiferson
Copy link
Member

Thanks @twmb

@twmb twmb deleted the clean_close_521 branch March 24, 2015 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants