Skip to content

fix(stream): wrap close done ch with sync.Once#2537

Merged
mergify[bot] merged 2 commits intoaws:mainlinefrom
efekarakus:fix/sync-once-streamer
Jun 28, 2021
Merged

fix(stream): wrap close done ch with sync.Once#2537
mergify[bot] merged 2 commits intoaws:mainlinefrom
efekarakus:fix/sync-once-streamer

Conversation

@efekarakus
Copy link
Copy Markdown
Contributor

Today, stream.Stream is structured as:

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.

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.
@efekarakus efekarakus requested a review from a team as a code owner June 28, 2021 22:44
@efekarakus efekarakus requested review from bvtujo and removed request for a team June 28, 2021 22:44
Copy link
Copy Markdown
Contributor

@huanjani huanjani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious what happens if we try to close it twice.

@efekarakus
Copy link
Copy Markdown
Contributor Author

I'm curious what happens if we try to close it twice.

@huanjani PANIC 😱
Screen Shot 2021-06-26 at 3 15 07 PM

@mergify mergify bot merged commit 3d97212 into aws:mainline Jun 28, 2021
@efekarakus efekarakus deleted the fix/sync-once-streamer branch June 28, 2021 23:10
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.
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