-
Notifications
You must be signed in to change notification settings - Fork 422
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
Graceful Netty server shutdown in case of startup errors #3558
Graceful Netty server shutdown in case of startup errors #3558
Conversation
ff5b884
to
035cda1
Compare
Thanks! It would be good to include similar improvement for other netty servers (cats, zio, loom). Maybe you could add them to this PR? |
…wash/tapir into netty-binding-error-shutdown
Hey @kciesielski, sure, I will try to update those you mentioned as well |
Hey @kciesielski! I added support for other Netty-based servers. However, please keep in mind that I don't have too much experience with either Cats or Zio, so I hope I have fixed it correctly there🙂 |
server/netty-server/loom/src/main/scala/sttp/tapir/server/netty/loom/NettyIdServer.scala
Show resolved
Hide resolved
@goawash Thanks a lot for this contribution! I just added a small update to |
In case of an error during the start of Netty, e.g., when trying to bind to the same port, the Netty server doesn't release all resources. Due to that, the app's main thread keeps working and cannot gracefully shut down the process entirely. This happens because no resource cleanup is executed, and Event Loop is still working after Netty couldn't be started.
The bug is straightforward to reproduce:
Exception during binding io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
The motivation of this PR is to release allocated resources in case of a failed start of the Netty Server. I have done this fix for all Netty-based servers.