-
Notifications
You must be signed in to change notification settings - Fork 55
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
Broadcast notify on Buffer.Close #302
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #302 +/- ##
==========================================
+ Coverage 83.07% 83.10% +0.02%
==========================================
Files 39 39
Lines 2730 2728 -2
==========================================
- Hits 2268 2267 -1
+ Misses 336 335 -1
Partials 126 126
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -287,10 +287,7 @@ func (b *Buffer) Close() (err error) { | |||
b.mutex.Unlock() | |||
|
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.
this "section" is where the bad things happen
there was an assumption that concurrent reads would not happen so there may be other issues. if we read, write, read, close and the read, write, and read goroutines are all in the same gap between the critical section and channel op we could panic writing to a closed channel if close closes the channel before write sends. |
ah you're right on |
Description
This changes Close from being a "signaler" to a "broadcaster" of the notify condition. There's a small, but possible chance that between
Unlock
andselect
at the bottom ofRead
that we will have concurrent reads in the same position which means only once can receive a notify. If aClose
happens in between this time, one or more reads will be blocked. One such case where this happen is for an srtp and srtcp reader.In a simpler case, one read in the same position may miss a notify event during a Close. This affects any basic use of a *packetio.Buffer.
Reference issue
Fixes #298 and #299 (maybe)
I reproduced this with synchronization points at the critical point mentioned such that we start 2 reads, close before the select, and then continue the reads, at which point the test will time out. The new test, as such, is non-deterministic without the manual sync points.