-
Notifications
You must be signed in to change notification settings - Fork 64
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
Fix crash when the server drops and does not return #19
Fix crash when the server drops and does not return #19
Conversation
This adds a new test that closes the server and continue to write to it. It uncovered a bug with an unhandled nil pointer. It also uncovered some issues in the reconnection logic that were fixed at the same time.
This fixes moby downstream issue 35613 |
@mariussturm, @0cjs, @iporsut, @MiLk, can you review this bug fix? It fixes a problem that was missed when the server is goes completely offline. |
On it, but this is not trivial code. |
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 believe camelCase should be used instead of snake_case for variable and type names.
Couldn't you achieve the same result with a simpler code using Context cancellation?
func (r *TCPReader) listenUntilCloseSignal(signal chan string) { | ||
defer func() { signal <- "done" }() | ||
defer r.listener.Close() | ||
func (r *TCPReader) accepter(connections chan net.Conn) { | ||
for { | ||
conn, err := r.listener.Accept() | ||
if err != nil { | ||
break |
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 an error occurs here, I think this will have no effect on the program but to silently stop the acceptor.
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 the case, the thing with the whole tcpreader
is to be a test harness, that is the reason all the functions are unexported. I should probably rename it so that it is clear that it is a test harness. It could probably be refactored and cleaned up to expose the API, but I am not aware of any downstream projects that require a GELF TCP Reader.
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.
Ah yes, I forgot about that.
It's fine then 👍
gelf/tcpreader.go
Outdated
if sig == "stop" { | ||
break | ||
if len(conns) >= 1 { |
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.
Those 2 blocks being similar, could you refactor in a way which doesn't duplicate code?
This is the first time I hear about context, my go-fu is quite limited, but from what I read, I am not sure it would be cleaner than the multiple signals. The thing is that we need to be able to control the Am I missing something on the Context? |
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 forgot the tcpreader was used only for the tests.
Don't bother with contexts.
Writer related code LGTM
func (r *TCPReader) listenUntilCloseSignal(signal chan string) { | ||
defer func() { signal <- "done" }() | ||
defer r.listener.Close() | ||
func (r *TCPReader) accepter(connections chan net.Conn) { | ||
for { | ||
conn, err := r.listener.Accept() | ||
if err != nil { | ||
break |
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.
Ah yes, I forgot about that.
It's fine then 👍
Thanks for the PR, LGTM! |
This adds a new test that closes the server and continue to
write to it. It uncovered a bug with an unhandled nil pointer. It
also uncovered some issues in the reconnection logic that were fixed
at the same time.