fix(ads): check if channel is closed #13
Open
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.
We have observed that sometimes writing to the channel happens when the channel is already closed. This issue is related to #1023.
Upon reviewing the code, I found that the
value
channel can be created by one goroutine, while a different goroutine handles sending data on this channel. The first goroutine depends on the existence of the stream and requests, while the second one is triggered fromSetSnapshot
, which operates with a different context than the server.There appears to be a race condition where the stream is canceled, and resources start to be cleaned up, while the context in
SetSnapshot
might cancel later, leading to writing on a closed channel.This is not a complete fix but should prevent the panic. We should aim to fix this by possibly keeping the context within the watch and checking for its cancellation, or other?