Skip to content

Commit

Permalink
Fix race condition in Packet.MarshalTo()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aler9 committed Jul 28, 2023
1 parent ce70bc1 commit 2552a6d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 1 deletion.
1 change: 0 additions & 1 deletion packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ func (p Packet) Marshal() (buf []byte, err error) {

// MarshalTo serializes the packet and writes to the buffer.
func (p *Packet) MarshalTo(buf []byte) (n int, err error) {
p.Header.Padding = p.PaddingSize != 0
n, err = p.Header.MarshalTo(buf)
if err != nil {
return 0, err
Expand Down
1 change: 1 addition & 0 deletions packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ func TestBasic(t *testing.T) {
}},
},
Version: 2,
Padding: true,
PayloadType: 96,
SequenceNumber: 27023,
Timestamp: 3653407706,
Expand Down

0 comments on commit 2552a6d

Please sign in to comment.