-
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
Support graceful shutdown in Netty server #3294
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
83a2e80
wip
kciesielski 3b01dcf
wip
kciesielski 7bc814f
Implement graceful shutdown for ZIO
kciesielski e5ac16f
Reject requests during shutdown
kciesielski 03dc2b8
Cleanup
kciesielski 04d71cb
Update Cats Effect Netty example
kciesielski a1a4855
Fix closing of ChannelGroup
kciesielski d452001
Remove redundant file
kciesielski 5b61c6c
Disable graceful shutdown in current Netty tests
kciesielski b8a4c2b
Test FutureServer for graceful shutdown
kciesielski 6341264
Adjust tests
kciesielski 610e128
Document graceful shutdown
kciesielski e74341a
Remove debug code
kciesielski f33b861
Remove unneeded dependencies
kciesielski 4b5cb55
Add stub implementations
kciesielski f2eacdc
Review fixes
kciesielski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,21 @@ NettyFutureServer(NettyFutureServerOptions.customiseInterceptors.serverLog(None) | |
NettyFutureServer(NettyConfig.defaultNoStreaming.socketBacklog(256)) | ||
``` | ||
|
||
## Graceful shutdown | ||
|
||
A Netty should can be gracefully closed using function `NettyFutureServerBinding.stop()` (and analogous functions available in Cats and ZIO bindings). This function ensures that the server will wait at most 10 seconds for in-flight requests to complete, while rejecting all new requests with 503 during this period. Afterwards, it closes all server resources. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should can? ;) maybe just run it through chatgpt to iron out the english :) |
||
You can customize this behavior in `NettyConfig`: | ||
|
||
```scala mdoc:compile-only | ||
import sttp.tapir.server.netty.NettyConfig | ||
import scala.concurrent.duration._ | ||
|
||
// adjust the waiting time to your needs | ||
val config = NettyConfig.defaultNoStreaming.withGracefulShutdownTimeout(5.seconds) | ||
// or if you don't want the server to wait for in-flight requests | ||
val config2 = NettyConfig.defaultNoStreaming.noGracefulShutdown | ||
``` | ||
|
||
## Domain socket support | ||
|
||
There is possibility to use Domain socket instead of TCP for handling traffic. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that temporary for development or a new requirement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is useful for development, when one wants to run examples with
examples/runMain a.b.c.HelloExample
and terminate a running server.