Skip to content

TCP memory leak when aborting the initiating request when using a pipe #19198

Description

@scic

I have a server that processes a GET request from the browser by issuing a GET request to another server. I use a pipe to forward the response.

http.createServer(function (req, res) {
  var url = 'http://jsonplaceholder.typicode.com/photos';
  var connector = http.get(url, received => received.pipe(res));
  req.pipe(connector);
}).listen(9001);

The problem is if the browser aborts the request then tcp memory gets leaked. The mem field of the following output keeps getting bigger until the server is restarted or the limit in /proc/sys/net/ipv4/tcp_mem is reached.

cat /proc/net/sockstat 
sockets: used 9243
TCP: inuse 7591 orphan 0 tw 7659 alloc 7671 mem 504111

After a while this might lead to an TCP: out of memory exception in the syslog (Happend on a CentOS but not on a Ubuntu):
kernel: TCP: out of memory -- consider tuning tcp_mem

If the server is stopped then the memory is released without stopping the memory is never recovered.

I tried to provide a simple example in https://gist.github.com/scic/466db4687f62fa23c0bc059c31ae179a.

I expect abort events to be automatically propagated to the piped stream or at least that the piped stream is properly destroyed.
Or must this be manually cleaned up and how?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions