-
Notifications
You must be signed in to change notification settings - Fork 111
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
Make Packet.MarshalTo() thread-safe #168
Conversation
Codecov Report
@@ Coverage Diff @@
## master #168 +/- ##
==========================================
- Coverage 86.32% 86.31% -0.01%
==========================================
Files 15 15
Lines 1638 1637 -1
==========================================
- Hits 1414 1413 -1
Misses 195 195
Partials 29 29
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
0743dc5
to
2c3722f
Compare
This issue was discovered through gortsplib's unit tests - in the tests, there's a dummy |
Thank you @aler9 . This would mean call sites would have set the proper flags which is fine. I am not totally happy about the handling of padding myself. But, I have not found a better way. Just to give a bit of history about the changes I made
I think it is fine that call sites have to provide the proper |
@boks1971 i would have done it the same way. I also thought about dropping the padding, but i think that this choice must be left to the user. This library should just be able to unmarshal any compliant RTP packet and marshal it as it is. I like bijective functions: every output corresponds to only one input and vice-versa. As for my user case, i use this library for handling RTP packets generated by cameras, and they add a lot of padding that can be filtered without problems. |
A Marshal function shouldn't change any property of the object that is being marshaled. Otherwise, Marshal() is non-thread safe and can't be called by multiple goroutines in parallel. PR pion#155 makes Packet.Marshal() set the Packet.Header.Padding bit when Packet.PaddingSize is non-zero; while this is preferable from the user point of view, it doesn't allow thread safety. This patch fixes the issue.
This was already fixed by pion#168 but got lost in pion#227. in SFUs, in order to distribute a packet to all clients, MarshalTo() is called in parallel by multiple routines, causing a race condition because the padding flag is dynamically set inside MarshalTo(). This is particular annoying when running automated tests. This PR fixes the issue by removing this write operation as discussed in pion#168.
This was already fixed by #168 but got lost in #227. in SFUs, in order to distribute a packet to all clients, MarshalTo() is called in parallel by multiple routines, causing a race condition because the padding flag is dynamically set inside MarshalTo(). This is particular annoying when running automated tests. This PR fixes the issue by removing this write operation as discussed in #168.
Description
A Marshal function shouldn't change any property of the object that is being marshaled. Otherwise, Marshal() is non-thread safe
and can't be called by multiple goroutines in parallel.
PR #155 makes Packet.Marshal() set the Packet.Header.Padding bit when Packet.PaddingSize is non-zero; while this is preferable from the user point of view, it breaks thread safety.
This patch fixes the issue.