shutdownWithJvm

fun Server.shutdownWithJvm(maxWaitTime: Duration)

Registers a JVM shutdown hook that gracefully shuts down this gRPC Server.

The hook runs shutdownGracefully, which waits up to maxWaitTime for in-flight RPCs and then forces the server down. Because the hook runs as the JVM exits, with no caller left to report to, a failure is swallowed — the server is stopped either way.

Extension function on Server.

Parameters

maxWaitTime

the maximum duration to wait for in-flight RPCs to complete before forcing shutdown

Throws

if maxWaitTime is under a millisecond, the resolution shutdownGracefully works in. This is checked here, when the hook is registered, rather than at JVM exit, where it would stop the shutdown from running at all.