feat: add graceful shutdown for k8s deployments#365
Conversation
Add nova:graceful_shutdown/0 that suspends the ranch listener, drains active connections with a configurable timeout, then stops the listener. Called automatically via prep_stop/1 during application shutdown. Configurable via sys.config: - shutdown_delay: ms to wait before suspending (default 0) - shutdown_drain_timeout: max ms to wait for connections to drain (default 15000) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ranch:info/1 returns a map in ranch 2.x, not a proplist. Match on map keys directly to satisfy dialyzer. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
burbas
left a comment
There was a problem hiding this comment.
Should not this behavior be implemented as a callback? Then it will automatically be invoked when calling application:stop(nova) or when the beam machine is shutting down.
|
I can look into it |
|
But looking at it prep_stop is a callback that is called if application is closed. https://www.erlang.org/doc/apps/kernel/application.html#c:prep_stop/1 so during prep_stop we will do some things before the stop? |
You are right. This needs to go into the |
|
So my suggestion is that we move the |
Only called from prep_stop/1, no reason to export from nova.erl.
2d5f481 to
b4ea5ee
Compare
Summary
nova:graceful_shutdown/0public API that handles the full shutdown sequence: delay → suspend listener → drain connections → stop listenerprep_stop/1during application shutdown (SIGTERM)shutdown_delay— ms to wait before suspending (lets k8s remove pod from endpoints, default 0)shutdown_drain_timeout— max ms to wait for in-flight requests to complete (default 15000)Test plan
🤖 Generated with Claude Code