containerd / ttrpc

GRPC for low-memory environments
Apache License 2.0
558 stars 80 forks source link

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

Closed klihub closed 1 week ago

klihub commented 1 month ago

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 verify after a Shutdown() a final ErrServerClosed error from Serve() it gets stuck forever.