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

Fix crash when the server drops and does not return #19

Merged
merged 4 commits into from
Dec 11, 2017
Merged

Fix crash when the server drops and does not return #19

merged 4 commits into from
Dec 11, 2017

Conversation

ghislainbourgeois
Copy link

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 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.
@CLAassistant
Copy link

CLAassistant commented Dec 6, 2017

CLA assistant check
All committers have signed the CLA.

@ghislainbourgeois
Copy link
Author

This fixes moby downstream issue 35613

@ghislainbourgeois
Copy link
Author

@mariussturm, @0cjs, @iporsut, @MiLk, can you review this bug fix? It fixes a problem that was missed when the server is goes completely offline.

@mariussturm
Copy link

On it, but this is not trivial code.

Copy link

@MiLk MiLk left a 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
Copy link

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.

Copy link
Author

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.

Copy link

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 👍

if sig == "stop" {
break
if len(conns) >= 1 {
Copy link

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?

@ghislainbourgeois
Copy link
Author

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 tcpreader test harness to drop only active connections, or the whole server synchronously with the test itself.

Am I missing something on the Context?

Copy link

@MiLk MiLk left a 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
Copy link

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 👍

@mariussturm
Copy link

Thanks for the PR, LGTM!

@mariussturm mariussturm merged commit 4143646 into Graylog2:v2 Dec 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants