Skip to content

drpcmanager: derive shutdown waiting from active streams - #82

Open
shubhamdhama wants to merge 1 commit into
cockroachdb:mainfrom
shubhamdhama:remove-wg-from-manager
Open

drpcmanager: derive shutdown waiting from active streams#82
shubhamdhama wants to merge 1 commit into
cockroachdb:mainfrom
shubhamdhama:remove-wg-from-manager

Conversation

@shubhamdhama

@shubhamdhama shubhamdhama commented Jul 22, 2026

Copy link
Copy Markdown

Each manageStream goroutine corresponds to one activeStreams entry.
Keeping a separate WaitGroup duplicated that lifecycle state and made
activeStreams.Add update synchronization owned by Manager.

Keep canceled streams registered until their manage goroutines remove
them. Once shutdown starts and the registry is empty, close a completion
channel so Manager.Close can wait on the registry itself. The registry
mutex keeps stream admission atomic with shutdown.

Use the same mutex to guard the one-time channel close. Cover both
admission orderings and verify that Wait blocks until Close and all
registered streams are removed.

@Nukitt
Nukitt requested a review from roachdev-claude July 23, 2026 13:24
@shubhamdhama
shubhamdhama requested review from roachdev-claude and removed request for roachdev-claude July 27, 2026 07:33

@Nukitt Nukitt 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.

lgtm!

// Manager.NewClientStream (newStream → create streamadd to streams). The
// activeStreams lock ensures a stream is either registered before Close starts
// waiting for the collection to drain or rejected after shutdown begins.
func TestManager_ConcurrentCloseAndNewClientStream(t *testing.T) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

not a blocker- do we also want a test that can force a different goroutine to win terminate? will have better coverage.

@suj-krishnan suj-krishnan 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.

LGTM! This is definitely more elegant than what we have today. Please check the nit and the test-gaps.

Comment thread drpcmanager/active_streams.go Outdated
// Manager.NewClientStream (newStream → create stream, add to streams, wg.Add).
// Under -race this would fail without wg.Add being atomic with the closed
// check in activeStreams.Add.
// Manager.NewClientStream (newStream → create streamadd to streams). The

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We can add tests around a few scenarios that we have explicitly guarded against (please ignore if the existin tests already cover these).

  • Two active streams: remove only the first, verify that Wait does not unblock
  • Test that Wait on an empty but open registry blocks until Close.
  • Remove streams before Close and verify that Close wakes an existing waiter.

Each manageStream goroutine corresponds to one activeStreams entry.
Keeping a separate WaitGroup duplicated that lifecycle state and made
activeStreams.Add update synchronization owned by Manager.

Keep canceled streams registered until their manage goroutines remove
them. Once shutdown starts and the registry is empty, close a completion
channel so Manager.Close can wait on the registry itself. The registry
mutex keeps stream admission atomic with shutdown.

Use the same mutex to guard the one-time channel close. Cover both
admission orderings and verify that Wait blocks until Close and all
registered streams are removed.

Co-authored-by: Cursor <cursoragent@cursor.com>
@shubhamdhama
shubhamdhama force-pushed the remove-wg-from-manager branch from aace5c2 to 7404483 Compare July 29, 2026 07:56
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