Skip to content

http - calls from an external IP close after 5-20 seconds using response.end and Content-Length header is set (Node 8.X) #14869

Closed
@mtraynham

Description

@mtraynham
  • Version: v8.0.0, v8.1.0, v8.4.0
  • Platform: Linux 4.10.0-28-generic 32~16.04.2-Ubuntu SMP Thu Jul 20 10:19:48 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux, Linux 2.6.32-573.3.1.el6.x86_64 1 SMP Thu Aug 13 22:55:16 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: http

Executing a request from an external IP address, results in a closed connection after about 5 - 20 seconds when the Content-Length header is set. When Content-Length is not set, it seems ok.
Executing a request locally always seems to respect the server timeout regardless of Content-Length.

This works correctly in Node 7.10.1.

Using the following code (thanks to Doug Wilson at ExpressJS):

var fs = require('fs');
var http = require('http');
var wordsFile = '/usr/share/dict/words';
function app (req, res) {
    switch (req.url) {
        case '/send':
            var contents = fs.readFileSync(wordsFile);
            res.setHeader('Content-Length', contents.length);
            res.end(contents);
            break;
        case '/sendNoLength':
            var contents = fs.readFileSync(wordsFile);
            res.end(contents);
            break;
        default:
            res.statusCode = 404;
            res.end();
    }
}
var server = http.createServer(app);
server.timeout = 120000 * 5;
server.listen('3000');

I've changed my IPs here to Google's...

> wget 8.8.8.8:3000/send --limit-rate=5k

--2017-08-16 18:03:56--  http://8.8.8.8:3000/send
Connecting to 8.8.8.8:3000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 938848 (917K)
Saving to: “send” --- 64,990      5.00K/s   in 13s     

2017-08-16 18:04:09 (5.00 KB/s) - Connection closed at byte 64990. Retrying.

--2017-08-16 18:04:10--  (try: 2)  http://8.8.8.8:3000/send
Connecting to 8.8.8.8:3000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 938848 (917K)
Saving to: “send” --- 67,724      5.00K/s   in 13s     

2017-08-16 18:04:23 (5.00 KB/s) - Connection closed at byte 67724. Retrying.

--2017-08-16 18:04:25--  (try: 3)  http://8.8.8.8:3000/send
Connecting to 8.8.8.8:3000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 938848 (917K)
Saving to: “send”  --- 62,256      5.00K/s   in 12s     

2017-08-16 18:04:37 (5.00 KB/s) - Connection closed at byte 67724. Retrying.

--2017-08-16 18:04:40--  (try: 4)  http://8.8.8.8:3000/send
Connecting to 8.8.8.8:3000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 938848 (917K)
Saving to: “send” --- 64,990      5.00K/s   in 13s     

2017-08-16 18:04:53 (5.00 KB/s) - Connection closed at byte 67724. Retrying.

It works when you don't set the Content-Length header:

> wget 8.8.8.8:3000/sendNoLength --limit-rate=5k

--2017-08-16 18:22:49--  http://8.8.8.8:3000/sendNoLength
Connecting to 8.8.8.8:3000... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified
Saving to: “sendNoLength”

2017-08-16 18:25:52 (5.00 KB/s) - “sendNoLength” saved [938848]

Paper trail of how I got here
angular/angular-cli#7197
webpack/webpack-dev-server#1044
expressjs/express#3392

Metadata

Metadata

Assignees

No one assigned

    Labels

    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