Skip to content

fs / streams: file descriptor leak on connection abort #1834

@bnoordhuis

Description

@bnoordhuis

From nodejs/node-v0.x-archive#6041 (comment):

var http = require('http');
var fs = require('fs');

var filename = process.argv[0];
var filesize = fs.statSync(filename).size;

http.createServer(function(req, res){
  var file = fs.createReadStream(filename);
  res.writeHead(200, { 'Content-Length': '' + filesize });
  // uncommenting the line below fixes the fd leak
  //res.on('close', file.destroy.bind(file));
  file.pipe(res);
}).listen(8080);

Hit with ab but ^C before it completes and check the open files afterwards:

$ ab -c 1000 -n 1000 http://127.0.0.1:8080/
^C

$ lsof -p $(pgrep iojs) | wc -l
928

$ ab -c 1000 -n 1000 http://127.0.0.1:8080/
^C

$ lsof -p $(pgrep iojs) | wc -l
1928

$ ab -c 1000 -n 1000 http://127.0.0.1:8080/
^C

$ lsof -p $(pgrep iojs) | wc -l
2791

# etc.

I think we should assign some prio to this even if it's an old bug because it's a great way to DoS a server.

/cc @nodejs/streams

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions