Skip to content

fix(p2p): make Client.Stop idempotent (#105)#106

Merged
LiranCohen merged 1 commit into
mainfrom
fix/p2p-stop-idempotent
Jun 8, 2026
Merged

fix(p2p): make Client.Stop idempotent (#105)#106
LiranCohen merged 1 commit into
mainfrom
fix/p2p-stop-idempotent

Conversation

@LiranCohen

Copy link
Copy Markdown
Contributor

Summary

Closes audit finding #34. Stop() did close(c.quit) with no guard (unlike syncOnce for the synced channel), so a double Stop — a defer plus an explicit shutdown, or two concurrent shutdown paths — panics with "close of closed channel". Latent today, but a fragile contract for an exported lifecycle method.

Fix

Guard the close with a sync.Once (stopOnce), mirroring syncOnce.

TestStopIsIdempotent calls Stop() twice and asserts no panic. go test -race ./... green (26 packages).

Post-Deploy Monitoring & Validation

No additional operational monitoring required: this only removes a latent panic on a redundant Stop; shutdown behavior is otherwise unchanged.

Closes #105

🤖 Generated with Claude Code

Finding #34. Stop() did close(c.quit) with no guard, so a double Stop (a defer plus
an explicit shutdown, or two concurrent shutdown paths) panics with "close of closed
channel". Guard the close with a sync.Once (stopOnce), mirroring syncOnce.

Test: TestStopIsIdempotent calls Stop twice and asserts no panic. go test -race
./... green.

Co-authored-by: Liran Cohen <liranlasvegas@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@LiranCohen LiranCohen merged commit a0589f6 into main Jun 8, 2026
1 check passed
@LiranCohen LiranCohen deleted the fix/p2p-stop-idempotent branch June 8, 2026 03:14
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.

p2p: Client.Stop is not idempotent (double Stop panics on closed channel)

1 participant