Skip to content
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

Fix race condition in Packet.MarshalTo() #234

Merged
merged 1 commit into from
Jul 28, 2023
Merged

Conversation

aler9
Copy link
Member

@aler9 aler9 commented Jul 28, 2023

Description

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.

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.
@aler9 aler9 requested review from stv0g and Sean-Der July 28, 2023 19:28
@codecov
Copy link

codecov bot commented Jul 28, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.01% ⚠️

Comparison is base (ce70bc1) 87.39% compared to head (2552a6d) 87.38%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #234      +/-   ##
==========================================
- Coverage   87.39%   87.38%   -0.01%     
==========================================
  Files          20       20              
  Lines        1888     1887       -1     
==========================================
- Hits         1650     1649       -1     
  Misses        207      207              
  Partials       31       31              
Flag Coverage Δ
go 87.38% <ø> (-0.01%) ⬇️
wasm 86.80% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
packet.go 88.01% <ø> (-0.04%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aler9 aler9 merged commit 7c80fd2 into pion:master Jul 28, 2023
@aler9 aler9 deleted the patch-168 branch July 28, 2023 19:30
@0x5e
Copy link

0x5e commented Aug 1, 2023

Hi @aler9 , Upgrade from 1.8.0 to 1.8.1, my h264 stream is broken. I have set rtpHeader.Padding = true before, and remove this made the stream ok again.
Is it required that we must not set the rtpHeader.Padding value?

@aler9
Copy link
Member Author

aler9 commented Aug 1, 2023

@0x5e on the contrary, it is required to set Header.Padding to true before calling MarshalTo when there's padding.

in my opinion, MarshalTo() must be a read-only function exactly like it is in all other objects and in the standard library. Otherwise it's impossible to safely pass packets between routines.

@aler9
Copy link
Member Author

aler9 commented Aug 1, 2023

Eventually we could add a consistency check in MarshalTo that returns an error when Header.Padding is true and PaddingSize is zero.

@0x5e
Copy link

0x5e commented Aug 1, 2023

Sorry that was my mistake, actually I need is Padding=false, so Header.Padding=true and PaddingSize=0 make me broken :)

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.

3 participants