From 482fbe2cf7d030e4b79d2995f0e94ff6a9670100 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Wed, 16 Sep 2026 02:59:09 +0530 Subject: [PATCH] sfu: skip pacer allocation assertion under the race detector (#4874) sync.Pool drops a quarter of returned items when built with -race, so the pooled send path averages about one allocation per packet in CI and the zero-allocation assertion flips between passing and failing. Keep the extension checks and skip only the allocation count under race. Co-authored-by: Claude Fable 5.1 --- pkg/sfu/pacer/base_test.go | 5 ++++- pkg/sfu/utils/norace.go | 6 ++++++ pkg/sfu/utils/race.go | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 pkg/sfu/utils/norace.go create mode 100644 pkg/sfu/utils/race.go diff --git a/pkg/sfu/pacer/base_test.go b/pkg/sfu/pacer/base_test.go index 3b68fa168..3842203a6 100644 --- a/pkg/sfu/pacer/base_test.go +++ b/pkg/sfu/pacer/base_test.go @@ -24,6 +24,7 @@ import ( "github.com/livekit/protocol/logger" "github.com/livekit/livekit-server/pkg/sfu/bwe" + "github.com/livekit/livekit-server/pkg/sfu/utils" ) // bwe.NullBWE is meant to be embedded and lacks Type @@ -80,5 +81,7 @@ func TestSendPacketHeaderExtensionsNoAlloc(t *testing.T) { require.Equal(t, 1002, w.writes) require.Equal(t, 3*w.writes, w.absSendTimeLen) require.Equal(t, 2*w.writes, w.transportWideLen) - require.Equal(t, 0.0, allocs, "allocations per SendPacket") + if !utils.RaceEnabled { + require.Equal(t, 0.0, allocs, "allocations per SendPacket") + } } diff --git a/pkg/sfu/utils/norace.go b/pkg/sfu/utils/norace.go new file mode 100644 index 000000000..ba683f0f7 --- /dev/null +++ b/pkg/sfu/utils/norace.go @@ -0,0 +1,6 @@ +//go:build !race + +package utils + +// RaceEnabled reports whether the binary was built with the race detector. +const RaceEnabled = false diff --git a/pkg/sfu/utils/race.go b/pkg/sfu/utils/race.go new file mode 100644 index 000000000..72223acef --- /dev/null +++ b/pkg/sfu/utils/race.go @@ -0,0 +1,8 @@ +//go:build race + +package utils + +// RaceEnabled reports whether the binary was built with the race detector. +// sync.Pool drops a quarter of returned items under it, so allocation counts +// on pooled paths are not meaningful. +const RaceEnabled = true