Fix data races with shared bytes.Buffer using concurrent.Buffer#2179
Merged
dgageot merged 1 commit intodocker:mainfrom Mar 19, 2026
Merged
Fix data races with shared bytes.Buffer using concurrent.Buffer#2179dgageot merged 1 commit intodocker:mainfrom
dgageot merged 1 commit intodocker:mainfrom
Conversation
Two independent data races were caused by unsynchronized bytes.Buffer access: 1. pkg/agent: TestModel_LogsSelection sets the global slog default to a handler backed by a bytes.Buffer. Parallel tests (TestModelOverride, TestModelOverride_ConcurrentAccess) also call Agent.Model() which triggers slog.Info(), racing on the shared buffer. 2. pkg/tools/builtin: startLocked() uses a bytes.Buffer as cmd.Stderr. The os/exec goroutine writes to it while readNotifications reads and resets it on a ticker. Introduce concurrent.Buffer — a mutex-protected bytes.Buffer — in the existing pkg/concurrent package (alongside Map and Slice) and use it in both locations. Assisted-By: docker-agent
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
This PR correctly fixes two data races by introducing a thread-safe concurrent.Buffer wrapper around bytes.Buffer. The implementation properly uses mutexes to protect all buffer operations (Write, String, Reset, and the atomic Drain method).
Changes reviewed:
- ✅ New
concurrent.Buffertype with proper mutex protection - ✅ Test code updated to use concurrent-safe buffer for shared slog handler
- ✅ LSP stderr handling updated to use concurrent-safe buffer
- ✅ Atomic
Drain()method prevents read-reset race conditions
No bugs found in the changed code. The fix is well-designed and addresses the root cause of the data races described in the PR.
rumpl
approved these changes
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two independent data races were caused by unsynchronized bytes.Buffer access:
pkg/agent: TestModel_LogsSelection sets the global slog default to a handler backed by a bytes.Buffer. Parallel tests (TestModelOverride, TestModelOverride_ConcurrentAccess) also call Agent.Model() which triggers slog.Info(), racing on the shared buffer.
pkg/tools/builtin: startLocked() uses a bytes.Buffer as cmd.Stderr. The os/exec goroutine writes to it while readNotifications reads and resets it on a ticker.
Introduce concurrent.Buffer — a mutex-protected bytes.Buffer — in the existing pkg/concurrent package (alongside Map and Slice) and use it in both locations.
Assisted-By: docker-agent