Feature Request: Implement graceful shutdown to prevent dropped connections
what problem would this feature solve, if any?
When the server is restarted or shut down, active connections are abruptly terminated. This leads to client-side errors such as curl: (52) Empty reply from server, especially during deployments or when handling ongoing requests. This also aims to resolve the underlying problems mentioned in #301.
describe the solution you'd like Implement a graceful shutdown mechanism for the server. Upon receiving a termination signal (e.g., SIGINT or SIGTERM), the server should immediately stop accepting new connections but wait for all currently processing requests to finish before completely shutting down.
describe alternatives you've considered
- Client-side retries: While helpful, this doesn't solve the root cause of dropped connections and might lead to duplicated operations if the requests aren't idempotent.
- Reverse proxy connection draining: Handling this at the load balancer or proxy level is possible, but having native graceful shutdown support in the application is much more robust and simplifies deployment setups.
additional context: Implementing this is crucial for achieving zero-downtime deployments and ensuring overall service reliability. Resolves #301.
Source: tiagozip/cap