-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Conversation
@@ -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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, changed.
fixes #521 |
@@ -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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
👍 |
nsqd: do not print EOF when closing cleanly
Thanks @twmb |
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.