Skip to content

drpcmanager: fix data race between newStream and Close on WaitGroup#77

Merged
shubhamdhama merged 1 commit into
mainfrom
fix-testAuthV2
Jul 17, 2026
Merged

drpcmanager: fix data race between newStream and Close on WaitGroup#77
shubhamdhama merged 1 commit into
mainfrom
fix-testAuthV2

Conversation

@Nukitt

@Nukitt Nukitt commented Jul 16, 2026

Copy link
Copy Markdown

Move wg.Add(1) inside activeStreams.Add under its mutex so the
increment and the closed check are atomic. This prevents wg.Add
racing with wg.Wait in Manager.Close when terminate closes streams
before newStream finishes registering.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a concurrency bug in drpcmanager.Manager where a sync.WaitGroup increment in newStream could race with wg.Wait() during Manager.Close(). It does this by making “stream registration + wg.Add” atomic with respect to termination/close.

Changes:

  • Move wg.Add(1) into activeStreams.Add under the activeStreams mutex, and pass &m.wg from Manager.newStream.
  • Add a regression test that concurrently calls Manager.Close() and Manager.NewClientStream() under contention.
  • Update activeStreams tests to match the updated Add signature.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
drpcmanager/manager.go Passes the manager WaitGroup into stream registration so wg.Add is coordinated with the closed check.
drpcmanager/active_streams.go Updates Add to optionally increment a WaitGroup under the same lock used for the closed check.
drpcmanager/manager_test.go Adds a concurrent Close vs NewClientStream regression test.
drpcmanager/active_streams_test.go Updates callers to the new activeStreams.Add(..., wg) signature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread drpcmanager/manager_test.go Outdated
Comment thread drpcmanager/manager_test.go
Comment thread drpcmanager/manager_test.go
Comment thread drpcmanager/manager_test.go
Move `wg.Add(1)` inside `activeStreams.Add` under its mutex so the
increment and the closed check are atomic. This prevents `wg.Add`
racing with `wg.Wait` in `Manager.Close` when terminate closes streams
before `newStream` finishes registering.
@shubhamdhama
shubhamdhama merged commit 84e9935 into main Jul 17, 2026
3 checks passed
@shubhamdhama
shubhamdhama deleted the fix-testAuthV2 branch July 17, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants