From 7c80fd2e6d1bc061b8373fcb1e3d17a21b093de8 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Fri, 28 Jul 2023 21:18:06 +0200 Subject: [PATCH] Fix race condition in Packet.MarshalTo() 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. --- packet.go | 1 - packet_test.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/packet.go b/packet.go index 500c60f..7aebb14 100644 --- a/packet.go +++ b/packet.go @@ -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 diff --git a/packet_test.go b/packet_test.go index bc8f97a..3044c0d 100644 --- a/packet_test.go +++ b/packet_test.go @@ -254,6 +254,7 @@ func TestBasic(t *testing.T) { }}, }, Version: 2, + Padding: true, PayloadType: 96, SequenceNumber: 27023, Timestamp: 3653407706,