-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Ensure we always have called Add() on the inflight counter before we Wait() for it #450
Conversation
@@ -610,6 +611,7 @@ func (p *asyncProducer) retryHandler() { | |||
|
|||
func (p *asyncProducer) shutdown() { | |||
Logger.Println("Producer shutting down.") | |||
p.inFlight.Add(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.
I don't think this is necessary? If you create a wait group and then immediately Wait on it (without ever calling Add) it just returns right away...
I think, this could potentially be an issue: p := NewAsyncProducer(...)
p.Input() <- msg
p.Close() if the |
Oh interesting, you're right that's a legit issue. However, I'm not sure your patch fixes all the cases :) p := NewAsyncProducer(...)
p.Close()
p.Input() <- msg With your patch, if the input message is handled before the waiting goroutine wakes up, then we will increment the counter from 0 before immediately decrementing it... so I think we must stop doing the "increment+decrement" trick for messages we return with the shutting-down error as well. |
I don't really understand this one? |
|
(I assume you means I don't really see what the problem is: after calling AsyncClose(), no message will ever make it into the processing logic, and we always wait for all the messages being processed to be completed. The worst that can happen is that we wait a bit too long, for |
Ya, sorry
But it will still cause the wait counter to be |
OK, this is an improvement regardless so I'll merge it; I'll also make a PR which should (I hope) fix and demonstrate the other case I'm thinking of. |
Ensure we always have called Add() on the inflight counter before we Wait() for it
@eapache This is not the cause of #449, but fixes another a potential issue when using the waitgroup.