Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove readStream.destroy() call on timeout

It's causing a lot of errors on closing the fd, even after
I started checking the fd before destroying it. I suppose it's the
underlying stream implementation trying to destroy() a stream twice.

net:231
  close(fd);
  ^
Error: EBADF, Bad file descriptor
    at closeFD (net:231:3)
    at Stream.destroy (net:999:17)
    at Stream.<anonymous> (http:731:12)
    at Stream.emit (events:42:20)
    at Timer.callback (net:151:19)
    at node.js:221:9

Will have to look at the Stream source code to see if I can find the
problem. Till then, the file descriptors are automatically closed when
the readStream reaches the end, so antinode shouldn't leak file
descriptors.
  • Loading branch information...
commit e2a1b0a98a30b76882f3df711cab5e8f2c6e516a 1 parent e6187f5
@mhansen authored
Showing with 4 additions and 8 deletions.
  1. +3 −7 lib/antinode.js
  2. +1 −1  package.json
View
10 lib/antinode.js
@@ -11,7 +11,7 @@ var http = require('http'),
exports.default_settings = {
"timeout_milliseconds": 1000 * 30,
"hosts" : {},
- "port" : 8080,
+ "port" : 8080, /* a port that you don't need root to bind to */
"default_host" : {
"root" : process.cwd()
},
@@ -22,6 +22,7 @@ exports.log_levels = log.levels;
var settings;
var server;
+
exports.start = function(custom_settings, callback) {
settings = custom_settings || {};
settings.__proto__ = exports.default_settings;
@@ -135,17 +136,12 @@ function handle_request(path, req, resp) {
var readStream = fs.createReadStream(file);
}
catch (err) {
- log.debug("fs.createReadStream(",file,") error: ",sys.inspect(err));
+ log.debug("fs.createReadStream(",file,") error: ",sys.inspect(err,true));
return file_not_found();
}
send_headers(200, stats.size, mime.mime_type(file), stats.mtime);
- req.connection.addListener('timeout', function() {
- log.debug('timed out. destroying file read stream');
- readStream.destroy();
- });
-
readStream.addListener('open', function() {
log.debug("opened",path);
});
View
2  package.json
@@ -1,6 +1,6 @@
{ "name" : "antinode"
, "description" : "A simple web server for node.js"
-, "version" : "2.0.7"
+, "version" : "2.0.8"
, "author" : "Mark Hansen <mark@markhansen.co.nz>"
, "contributors" :
[ "Ben Noordhuis <info@bnoordhuis.nl>"
Please sign in to comment.
Something went wrong with that request. Please try again.