Skip to content

Hardcoded socket timeout #31378

Closed
Closed
@ghost

Description

Documentation states that sockets do not have timeout on by default:

Sets the socket to timeout after timeout milliseconds of inactivity on the socket. By default net.Socket do not have a timeout.

And yet, HTTP requests time out after 2 minutes. According to links below, the time out would be hardcoded but I couldn't find proof of this.

https://stackoverflow.com/a/46157120
https://forum.nginx.org/read.php?2,214230,214239#msg-214239

Test case

server.js

const {createServer} = require('http');

createServer(async (req, res) => {
        setTimeout(() => {
          res.end();
        }, 130000);
}).listen(1337);
$ node server.js
$ time curl -v localhost:1337
* Rebuilt URL to: localhost:1337/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 1337 (#0)
> GET / HTTP/1.1
> Host: localhost:1337
> User-Agent: curl/7.58.0
> Accept: */*
>
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server

real    2m0.094s
user    0m0.009s
sys     0m0.018s

Workaround

server.js

const {createServer} = require('http');

createServer(async (req, res) => {
        req.socket.setTimeout(0);

        setTimeout(() => {
          res.end();
        }, 130000);
}).listen(1337);
$ node server.js
$ time curl -v localhost:1337
* Rebuilt URL to: localhost:1337/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 1337 (#0)
> GET / HTTP/1.1
> Host: localhost:1337
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 16 Jan 2020 10:35:48 GMT
< Connection: keep-alive
< Content-Length: 0
<
* Connection #0 to host localhost left intact

real    2m10.057s
user    0m0.027s
sys     0m0.018s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions