Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: fix a Serve() vs. (immediate) Shutdown() race #175

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

klihub
Copy link
Member

@klihub klihub commented Sep 13, 2024

Fix a race where an asynchronous server.Serve() invoked in a a goroutine races with an almost immediate server.Shutdown().

If Shutdown() finishes its locked closing of listeners before Serve() gets around to add the new one, Serve will sit stuck forever in l.Accept(), unless the caller closes the listener in addition to Shutdown().

This is probably almost impossible to trigger in real life, but unit tests which run the server and client in the same process can trigger this. If a test then tries to verifyafter a Shutdown() a final ErrServerClosed error from Serve() it gets stuck forever.

@klihub klihub force-pushed the fixes/serve-listen-shutdown-race branch 2 times, most recently from f4a5a58 to 4ca1d79 Compare September 13, 2024 13:24
Fix a race where an asynchronous server.Serve() invoked in a
a goroutine races with an almost immediate server.Shutdown().
If Shutdown() finishes its locked closing of listeners before
Serve() gets around to add the new one, Serve will sit stuck
forever in l.Accept(), unless the caller closes the listener
in addition to Shutdown().

This is probably almost impossible to trigger in real life,
but some of the unit tests, which run the server and client
in the same process, occasionally do trigger this. Then, if
the test tries to verify a final ErrServerClosed error from
Serve() after Shutdown() it gets stuck forever.

Signed-off-by: Krisztian Litkey <[email protected]>
@klihub klihub force-pushed the fixes/serve-listen-shutdown-race branch from 4ca1d79 to c4d96d5 Compare September 16, 2024 06:53
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.

1 participant