armeria
armeria copied to clipboard
Provide a way to terminate unfinished requests after graceful shutdown
Motivation:
Unfinished requests even after graceful shutdown period are forcivily closed with ClosedSessionException. As ClosedSessionException indicates that the connection was unexpectedly disconnected, ClosedSessionException is not suitable for graceful shutdown.
In this PR, I propose to add ShuttingDownException to terminate unfinished requests when a server stops.
Modifications:
- Introduce
GracefulShutdownto customize graceful shutdown behavior.- Users can specify a error function to create an exception to unfinished terminate requests.
- Fixed
HttpServerHandlerto send error responses using the error function ofGracefulShutdown - Fixed
Serverto send error respones first and then close the connnections. - Deprecation)
ServerConfig.gracefulShutdownQuietPeriod()andServerConfig.gracefulShutdownTimeout()have been deprecated in favor ofServerConfig.gracefulShutdown().
Result:
You can now use GracefulShutdown to terminate unfinished requests when a server stops.
GracefulShutdown gracefulShutdown =
GracefulShutdown
.builder()
.quietPeriod(Duration.ofSeconds(10))
.timeout(Duration.ofSeconds(15))
.shutdownErrorFunction((ctx, req) -> {
return new ServerStopException();
})
.build();
Server
.builder()
.gracefulShutdown(gracefulShutdown);
🔍 Build Scan® (commit: f3f9b1f717fce5b6b0dae9049ec1de54b3662e3a)
| Job name | Status | Build Scan® |
|---|---|---|
| build-ubicloud-standard-8-jdk-8 | ✅ | https://ge.armeria.dev/s/ytcuyvikygk56 |
| build-ubicloud-standard-8-jdk-21-snapshot-blockhound | ✅ | https://ge.armeria.dev/s/aps7ijzua3p2g |
| build-ubicloud-standard-8-jdk-17-min-java-17-coverage | ✅ | https://ge.armeria.dev/s/yeml4gvwm77ru |
| build-ubicloud-standard-8-jdk-17-min-java-11 | ✅ | https://ge.armeria.dev/s/voyhpybbh5sj4 |
| build-ubicloud-standard-8-jdk-17-leak | ✅ | https://ge.armeria.dev/s/dynijahxidow2 |
| build-ubicloud-standard-8-jdk-11 | ❌ (failure) | https://ge.armeria.dev/s/ldqtccbuke3sk |
| build-macos-latest-jdk-21 | ✅ | https://ge.armeria.dev/s/ieamd53bc3tz6 |
Changed the target milestone to 1.32.0. I need some time to figure out how to implement the API that Trustin suggested.