Skip to content

fix: ws race and leak fixes#383

Merged
HealthyBuilder merged 1 commit into
solana-foundation:mainfrom
sonicfromnewyoke:fix/ws-race-and-leak-fixes
Apr 10, 2026
Merged

fix: ws race and leak fixes#383
HealthyBuilder merged 1 commit into
solana-foundation:mainfrom
sonicfromnewyoke:fix/ws-race-and-leak-fixes

Conversation

@sonicfromnewyoke
Copy link
Copy Markdown
Contributor

@sonicfromnewyoke sonicfromnewyoke commented Apr 9, 2026

Problem

ws client has a couple of concurency bugs:

  • goroutine and chan leaks on conn drop
  • no sync on the closed flag
  • Close() returning before background goroutines finished
  • Response() methods that leaked a goroutine per call. For example. WaitForConfirmation method leaks in the loop

Summary of Changes

  • added a per-subscription mutex to protect channel sends and closes
  • removed the fundamentally broken Response() and RecvWithTimeout() methods from all subscription wrappers, replacing their only caller with Recv + context timeout
  • added WaitGroup to Close so callers can rely on cleanup being complete
  • reduced channel buffers from 200K/100K to 200/1, which made error sends non-blocking to prevent deadlocks
  • extended unit tests to cover all the cases above with -race flag

closes #327
closes #334
closes #270

@HealthyBuilder HealthyBuilder merged commit 4370b70 into solana-foundation:main Apr 10, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants