-
Notifications
You must be signed in to change notification settings - Fork 158
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 sequential execution of connection state callbacks #656
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #656 +/- ##
==========================================
+ Coverage 78.84% 78.89% +0.04%
==========================================
Files 42 42
Lines 4444 4454 +10
==========================================
+ Hits 3504 3514 +10
Misses 722 722
Partials 218 218
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
agent.go
Outdated
@@ -278,7 +278,7 @@ func NewAgent(config *AgentConfig) (*Agent, error) { //nolint:gocognit | |||
|
|||
a := &Agent{ | |||
chanTask: make(chan task), | |||
chanState: make(chan ConnectionState), | |||
chanState: make(chan ConnectionState, 4), |
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.
Why 4 ?
Won't this deadlock if we get unlucky and there is 5 events queued up.
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.
We only need this to close the agent correctly. The current behaviour allows agent closing in the callback which with a channel capacity of 0 would lead to deadlock.
I will see what the right way to handle this is.
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.
Considering that we can go Connected to Disconnected to Connected many many times, I don't think a limit to the channel can work. Especially considering that we don't want to block the go routine sending to chanState.
So I've introduced a queue here which runs the callbacks in a separate goroutine
a069da8
to
dbc776c
Compare
Before we launched a goroutine to announce every ConnectionState change to users. These could then be sent to the user out of order. This commit adds a connectionStateNotifier. The connectionStateNotifier delivers them sequentially to the user. Resolves #624
dbc776c
to
59cc806
Compare
Ice update connection state callbacks need to happen sequentially otherwise a later callback could overwrite a newer callback.
Fixes: #624