Skip to content

Race condition when closing both server and client at the same time#43

Closed
yyewolf wants to merge 1 commit intovjeantet:masterfrom
yyewolf:master
Closed

Race condition when closing both server and client at the same time#43
yyewolf wants to merge 1 commit intovjeantet:masterfrom
yyewolf:master

Conversation

@yyewolf
Copy link
Copy Markdown

@yyewolf yyewolf commented Jul 5, 2024

We had a weird issue with test not working from time to time, turns out there's a race condition if you close both a server and a client at the same time.

Take this example :

client.Close()
server.Stop()

In this case, the goroutine might close the client channel, but receive the server closed message first, meaning that it would try to send to the closed channel.

@vjeantet
Copy link
Copy Markdown
Owner

This race condition has been fixed in commit f367b2e ("Fix WaitGroup data race in shutdown-listener goroutine").

The shutdown-listener goroutine no longer uses wg.Add/Done — it now uses a dedicated shutdownDone channel, and close() waits on it before calling wg.Wait(), which eliminates the race between concurrent server and client shutdown.

Thanks for reporting the issue.

@vjeantet vjeantet closed this Feb 17, 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.

2 participants