Skip to content

fix: prevent deadlock in gun.Conn.Close when initReader is in progress#2651

Merged
wwqgtxx merged 3 commits into
MetaCubeX:Alphafrom
beck-8:fix/gun-close-deadlock
Mar 29, 2026
Merged

fix: prevent deadlock in gun.Conn.Close when initReader is in progress#2651
wwqgtxx merged 3 commits into
MetaCubeX:Alphafrom
beck-8:fix/gun-close-deadlock

Conversation

@beck-8

@beck-8 beck-8 commented Mar 29, 2026

Copy link
Copy Markdown

Close() called initOnce.Do() which blocks if initReader is already running inside initFn (e.g. HTTP2 RoundTrip stuck on network I/O). This caused worker goroutines to hang forever during alive checks.

Fix: close the pipe writer first to unblock initFn, then call initOnce.Do() which is now guaranteed to return promptly.

Close() called initOnce.Do() which blocks if initReader is already
running inside initFn (e.g. HTTP2 RoundTrip stuck on network I/O).
This caused worker goroutines to hang forever during alive checks.

Fix: close the pipe writer first to unblock initFn, then call
initOnce.Do() which is now guaranteed to return promptly.

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

@wwqgtxx

wwqgtxx commented Mar 29, 2026

Copy link
Copy Markdown
Collaborator

I've revised the code to be clearer; you can test it to see if it resolves the deadlock issue.

@beck-8

beck-8 commented Mar 29, 2026

Copy link
Copy Markdown
Author

LGTM

@wwqgtxx wwqgtxx merged commit 719d3eb into MetaCubeX:Alpha Mar 29, 2026
@beck-8 beck-8 deleted the fix/gun-close-deadlock branch March 29, 2026 12:47
QuanWenG pushed a commit to StarHanami/CL.CoRE that referenced this pull request Mar 31, 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.

3 participants