Skip to content

fix: fix connection panic caused by WaitGroup misuse on close#1484

Open
nodece wants to merge 1 commit intoapache:masterfrom
nodece:fix/issue-1483-waitgroup-panic
Open

fix: fix connection panic caused by WaitGroup misuse on close#1484
nodece wants to merge 1 commit intoapache:masterfrom
nodece:fix/issue-1483-waitgroup-panic

Conversation

@nodece
Copy link
Copy Markdown
Member

@nodece nodece commented Apr 24, 2026

Fixes #1483

Motivation

When the connection is closed while SendRequest/SendRequestNoWait are in flight, failLeftRequestsWhenClose calls Wait() on the WaitGroup. Concurrent goroutines that pass the getState() check may still call Add(1), triggering sync: WaitGroup is reused before previous Wait has returned panic in Go 1.25+.

Modifications

  • Protect the state check and Add(1) under c.mu.RLock() in SendRequest and SendRequestNoWait. Close() sets state under c.mu.Lock(), so the check-and-add is atomic with respect to Close(). After state is set to connectionClosed, no new Add(1) can happen, ensuring Wait() will always return.
  • Replace the nil-sentinel goroutine drain with a non-blocking drain after Wait(). Since Wait() guarantees all requests are already enqueued, a non-blocking drain is sufficient for strict correctness.

@nodece nodece force-pushed the fix/issue-1483-waitgroup-panic branch from ed778ba to f070589 Compare April 24, 2026 11:29
@nodece nodece force-pushed the fix/issue-1483-waitgroup-panic branch from f070589 to 154a0ac Compare April 24, 2026 11:30
@nodece nodece changed the title [Issue 1483] Fix connection panic caused by WaitGroup misuse on close fix: fix connection panic caused by WaitGroup misuse on close Apr 24, 2026
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.

connection panic When close

1 participant