fix: synchronize compression changes during frame publish - #4
Conversation
kolkov
left a comment
There was a problem hiding this comment.
Real data race — PublishFrame reads c.codec four times without holding c.mu, while SetCompression writes it under lock. Concurrent callers could encode with one codec and label with another.
Fix is correct: RLock snapshot at the top of PublishFrame, released before the expensive Encode call so SetCompression is not blocked. All four codec references consistently use the local snapshot. The concurrent publish+compression test with 128 frames validates the fix under the race detector.
LGTM, merging.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
CI fails on all three PRs with the same config issue:
Could you drop the |
Summary
SetCompression/PublishFrameregression coverage with payload verificationRoot cause
SetCompressionreplacedClient.codecunderc.mu, whilePublishFrameread the interface repeatedly without synchronization. Concurrent callers triggered a data race and could encode a payload with one codec while labeling it with another.The lock is released before compression, so potentially expensive encoding does not block configuration changes. Codec implementations are already documented as concurrency-safe.
Verification
go test -count=1 ./...go test -race -count=1 ./...go build ./...go vet ./...go test -coverprofile=coverage.out -covermode=atomic ./...: repository 95.7%; changed coverable statements 100%gofmtandgit diff --checkThe new regression deterministically exposes the original race under the race detector and validates decoded frame integrity.
Current CI status
The upstream fork workflow for head
0cad3b7is awaiting maintainer approval in Actions run 31433849257. Until that approval, GitHub cannot publish the repository's Actions or Codecov checks/comments. Local changed-line coverage is 100%.