Cancellation and Application Shutdown in an HTTP Server11/02/2026
I work on a personal project to build an ASP.NET Core server to serves HTTP/2 and HTTP/3 request-response pairs. This server integrates with ASP.NET Core applications, providing an alternative to Kestrel, IIS, HTTP.sys, and similar servers.
In most codebases I've encountered, significant effort goes into optimizing the startup process—starting the host, registering types, initializing background services, and establishing downstream connections. The goal is usually to achieve the fastest and most efficient application initialization. However, it's much less common for applications to pay the same attention to the shutdown process. That’s the focus of this post.
For server applications, there's often an assumption that requests are retriable. If a request is interrupted due to application shutdown, the client can simply retry. However, HTTP only guarantees safe retries for idempotent verbs and compliant servers.
At the infrastructure level, sophisticated hosting solutions can drain all active HTTP connections before terminating the server process. In a less controlled environments, a process might be terminated abruptly, without draining connections or even sending a SIGINT (CTRL+C) or SIGTERM signal.