Repository navigation
http: memory leak if a server is not closed #48604
Copy link
Copy link
Closed
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.httpIssues and PRs related to the http subsystem.Issues and PRs related to the http subsystem.
Description
Activity
- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.httpIssues and PRs related to the http subsystem.Issues and PRs related to the http subsystem.
on Jun 29, 2023 To be honest I don't think this is a bug. It's like opening sockets and never closing them.
Sorry, my bad, I did not notice that there is no
server.listen()in the example, but anyway I think that the "leak" is expected with that sync loop.I can reproduce even with an async loop so it's not that.
This seems to fix the issue
diff --git a/lib/_http_server.js b/lib/_http_server.js index 0242e7a089..571ed15c6d 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -549,7 +549,7 @@ function Server(options, requestListener) { this.timeout = 0; this.maxHeadersCount = null; this.maxRequestsPerSocket = 0; - setupConnectionsTracking(this); + // setupConnectionsTracking(this); this[kUniqueHeaders] = parseUniqueHeadersOption(options.uniqueHeaders); } ObjectSetPrototypeOf(Server.prototype, net.Server.prototype);
cc: @ShogunPanda
Reacted by Matteo Collina and Marco IppolitoMaybe we should call
setupConnectionsTrackingonlistenevent ?It makes sense to me, there is no connection to track if the server is not listening.
That is fine, but it does not explain the leak. I'll try to dig into this in the next few days.
I think because the anonymous function hold the server object.
setInterval(checkConnections.bind(server), server.connectionsCheckingInterval).unref();
Yes, I confirm that is the issue. I'll move that call in a listen even as suggested.
Reacted by theanarkh
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.httpIssues and PRs related to the http subsystem.Issues and PRs related to the http subsystem.
Version
v18.16.1
Platform
Mac
Subsystem
http
What steps will reproduce the bug?
Run
How often does it reproduce? Is there a required condition?
All the time
What is the expected behavior? Why is that the expected behavior?
The memory should not grow uncontrolled
What do you see instead?
Memory growing and after many iterations a crash
Additional information
No response