Skip to content

Add ability to force close persistent connections #41578

Closed
@jsumners

Description

@jsumners

What is the problem this feature will solve?

As noted in https://nodejs.org/dist/latest-v16.x/docs/api/net.html#serverclosecallback, a net.Server will not fully close until all persistent (keep-alive) connections have reached the end of their timeout. In other languages/frameworks, e.g. Java, C#, or PHP, this is not a problem because applications written with them are typically hosted within a dedicated HTTP server that will deal with this on the application's behalf. However, if we look at another language in which applications are typically written to provide a direct HTTP server we can see that this problem showed up there and has been solved -- golang/go#4674 (comment) (final resolution https://go.dev/doc/go1.8#http_shutdown):

HTTP Server Graceful Shutdown
The HTTP Server now has support for graceful shutdown using the new Server.Shutdown method and abrupt shutdown using the new Server.Close method.

https://pkg.go.dev/net/http#Server.Close

What is the feature you are proposing to solve the problem?

I propose that Node.js internally track persistent connections and provide a method to forcefully close them.

What alternatives have you considered?

We have implemented a, what I would call hacky, solution for this in Fastify -- fastify/fastify#3619

The hope is that if Node.js internalizes it, it can be more performant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.httpIssues or PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions