-
Notifications
You must be signed in to change notification settings - Fork 6
Ensure coordinatorManager.Close() will eventually complete #3
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
|
@kentquirk @jh-bate Pls look at this. |
Contributor
|
LGTM - tests even :) |
cheddar
added a commit
that referenced
this pull request
Jul 29, 2014
Ensure coordinatorManager.Close() will eventually complete
ewollesen
added a commit
that referenced
this pull request
Mar 27, 2024
I believe there was confusion about how this is called or should run. These changes provide equivalent functionality, while being easier to read and understand. There are instructions from the library authors here: https://github.com/IBM/sarama/blob/v1.38.1/consumer_group.go#L19 I think there was confusion around the steps detailed in the link above. So let me clarify my understanding: - Canceling the context passed to Consume is how the implementor of the sarama.ConsumerGroupHandler tells Consume to return. In other words, when we're shutting down, we cancel the context to get Consume to return. I base this off of #4 in the link. - No goroutine needs to be launched on our side, the sarama library will launch the goroutines and those goroutines will call our implementation of ConsumeClaim(). This comes from #3. - The warnings about thread-safety apply to our implementation of ConsumeClaim(). In other words, we need to be careful that s.consumer isn't nil, but since nothing in our code modifies s.consumer after instantiation, we're fine. This comes from #3. - Since our own events.EventConsumer has to be able to respond to Stop() calls, we need to be able to break the for-loop in Start(), which is done by canceling the context that we pass to Consume(). The context.CancelFunc is guarded with a mutex for for extra thread-safety, so that if Stop() is called from multiple goroutines, we don't have any race conditions to worry about. We can reason that the goroutine being previously launched necessary, as there was only a single goroutine being launched, and same function that launched it then blocked, waiting for it to return before continuing. Without the goroutine, the WaitGroup and stop channel and stopOnce are no longer required.
ewollesen
added a commit
that referenced
this pull request
Mar 28, 2024
I believe there was confusion about how this is called or should run. These changes provide equivalent functionality, while being easier to read and understand. There are instructions from the library authors here: https://github.com/IBM/sarama/blob/v1.38.1/consumer_group.go#L19 I think there was confusion around the steps detailed in the link above. So let me clarify my understanding: - Canceling the context passed to Consume is how the implementor of the sarama.ConsumerGroupHandler tells Consume to return. In other words, when we're shutting down, we cancel the context to get Consume to return. I base this off of #4 in the link. - No goroutine needs to be launched on our side, the sarama library will launch the goroutines and those goroutines will call our implementation of ConsumeClaim(). This comes from #3. - The warnings about thread-safety apply to our implementation of ConsumeClaim(). In other words, we need to be careful that s.consumer isn't nil, but since nothing in our code modifies s.consumer after instantiation, we're fine. This comes from #3. - Since our own events.EventConsumer has to be able to respond to Stop() calls, we need to be able to break the for-loop in Start(), which is done by canceling the context that we pass to Consume(). The context.CancelFunc is guarded with a mutex for for extra thread-safety, so that if Stop() is called from multiple goroutines, we don't have any race conditions to worry about. We can reason that the goroutine being previously launched was not necessary, because there was only a single goroutine being launched, and the same function that launched the goroutine then blocked, waiting for it to exit before continuing. Without the goroutine, the WaitGroup, stop channel and stopOnce are no longer necessary.
ewollesen
added a commit
that referenced
this pull request
Apr 15, 2024
I believe there was confusion about how this is called or should run. These changes provide equivalent functionality, while being easier to read and understand. There are instructions from the library authors here: https://github.com/IBM/sarama/blob/v1.38.1/consumer_group.go#L19 I think there was confusion around the steps detailed in the link above. So let me clarify my understanding: - Canceling the context passed to Consume is how the implementor of the sarama.ConsumerGroupHandler tells Consume to return. In other words, when we're shutting down, we cancel the context to get Consume to return. I base this off of #4 in the link. - No goroutine needs to be launched on our side, the sarama library will launch the goroutines and those goroutines will call our implementation of ConsumeClaim(). This comes from #3. - The warnings about thread-safety apply to our implementation of ConsumeClaim(). In other words, we need to be careful that s.consumer isn't nil, but since nothing in our code modifies s.consumer after instantiation, we're fine. This comes from #3. - Since our own events.EventConsumer has to be able to respond to Stop() calls, we need to be able to break the for-loop in Start(), which is done by canceling the context that we pass to Consume(). The context.CancelFunc is guarded with a mutex for for extra thread-safety, so that if Stop() is called from multiple goroutines, we don't have any race conditions to worry about. We can reason that the goroutine being previously launched was not necessary, because there was only a single goroutine being launched, and the same function that launched the goroutine then blocked, waiting for it to exit before continuing. Without the goroutine, the WaitGroup, stop channel and stopOnce are no longer necessary.
ewollesen
added a commit
that referenced
this pull request
Feb 3, 2025
I believe there was confusion about how this is called or should run. These changes provide equivalent functionality, while being easier to read and understand. There are instructions from the library authors here: https://github.com/IBM/sarama/blob/v1.38.1/consumer_group.go#L19 I think there was confusion around the steps detailed in the link above. So let me clarify my understanding: - Canceling the context passed to Consume is how the implementor of the sarama.ConsumerGroupHandler tells Consume to return. In other words, when we're shutting down, we cancel the context to get Consume to return. I base this off of #4 in the link. - No goroutine needs to be launched on our side, the sarama library will launch the goroutines and those goroutines will call our implementation of ConsumeClaim(). This comes from #3. - The warnings about thread-safety apply to our implementation of ConsumeClaim(). In other words, we need to be careful that s.consumer isn't nil, but since nothing in our code modifies s.consumer after instantiation, we're fine. This comes from #3. - Since our own events.EventConsumer has to be able to respond to Stop() calls, we need to be able to break the for-loop in Start(), which is done by canceling the context that we pass to Consume(). The context.CancelFunc is guarded with a mutex for for extra thread-safety, so that if Stop() is called from multiple goroutines, we don't have any race conditions to worry about. We can reason that the goroutine being previously launched was not necessary, because there was only a single goroutine being launched, and the same function that launched the goroutine then blocked, waiting for it to exit before continuing. Without the goroutine, the WaitGroup, stop channel and stopOnce are no longer necessary.
ewollesen
added a commit
that referenced
this pull request
Mar 3, 2025
I believe there was confusion about how this is called or should run. These changes provide equivalent functionality, while being easier to read and understand. There are instructions from the library authors here: https://github.com/IBM/sarama/blob/v1.38.1/consumer_group.go#L19 I think there was confusion around the steps detailed in the link above. So let me clarify my understanding: - Canceling the context passed to Consume is how the implementor of the sarama.ConsumerGroupHandler tells Consume to return. In other words, when we're shutting down, we cancel the context to get Consume to return. I base this off of #4 in the link. - No goroutine needs to be launched on our side, the sarama library will launch the goroutines and those goroutines will call our implementation of ConsumeClaim(). This comes from #3. - The warnings about thread-safety apply to our implementation of ConsumeClaim(). In other words, we need to be careful that s.consumer isn't nil, but since nothing in our code modifies s.consumer after instantiation, we're fine. This comes from #3. - Since our own events.EventConsumer has to be able to respond to Stop() calls, we need to be able to break the for-loop in Start(), which is done by canceling the context that we pass to Consume(). The context.CancelFunc is guarded with a mutex for for extra thread-safety, so that if Stop() is called from multiple goroutines, we don't have any race conditions to worry about. We can reason that the goroutine being previously launched was not necessary, because there was only a single goroutine being launched, and the same function that launched the goroutine then blocked, waiting for it to exit before continuing. Without the goroutine, the WaitGroup, stop channel and stopOnce are no longer necessary.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In local development, I noticed that tide-whisperer was hanging on shutdown. I killed it again and got the following panic:
Which seems to indicate that there was a deadlock between coordinatorManager.Close() and coordinatorManager.getClients().
It appears that coordinatorManager.Close() was waiting on a receive on the close channel, but nothing was on the other end of it. So this PR introduces a timeout to that wait and returns an error if it wasn't able to successfully close.