fix(stream): wrap close done ch with sync.Once#2537
Merged
mergify[bot] merged 2 commits intoaws:mainlinefrom Jun 28, 2021
Merged
fix(stream): wrap close done ch with sync.Once#2537mergify[bot] merged 2 commits intoaws:mainlinefrom
mergify[bot] merged 2 commits intoaws:mainlinefrom
Conversation
Today, `stream.Stream` is structured as: ```go case <-streamer.Done(): // call Close() case <-time.After(fetchDelay): // call Fetch() ``` The problem is that it's possible that the Done() event is triggered at the same time as time.After(fetchDelay) and in that scenario the behavior is undeterministic. It's possible that we call `Fetch` a second time. For the ECS deployment streamer, this means that we would previous close the `s.done` channel twice. Wrapping the call with a `sync.Once` removes this concern.
huanjani
approved these changes
Jun 28, 2021
Contributor
huanjani
left a comment
There was a problem hiding this comment.
I'm curious what happens if we try to close it twice.
iamhopaul123
approved these changes
Jun 28, 2021
Contributor
Author
@huanjani PANIC 😱 |
thrau
pushed a commit
to localstack/copilot-cli-local
that referenced
this pull request
Dec 9, 2022
Today, `stream.Stream` is structured as: ```go case <-streamer.Done(): // call Close() case <-time.After(fetchDelay): // call Fetch() ``` The problem is that it's possible that the `Done()` event is triggered at the same time as `time.After(fetchDelay)` and in that scenario the behavior is undeterministic. It's possible that we call `Fetch` a second time. For the ECS deployment streamer, this means that we would previous close the `s.done` channel twice. Wrapping the call with a `sync.Once` removes this concern. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
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
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.

Today,
stream.Streamis structured as:The problem is that it's possible that the
Done()event is triggered atthe same time as
time.After(fetchDelay)and in that scenario thebehavior is undeterministic.
It's possible that we call
Fetcha second time. For the ECS deploymentstreamer, this means that we would previous close the
s.donechanneltwice. Wrapping the call with a
sync.Onceremoves this concern.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.