Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardcoded socket timeout #31378

Closed
ghost opened this issue Jan 16, 2020 · 2 comments
Closed

Hardcoded socket timeout #31378

ghost opened this issue Jan 16, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented Jan 16, 2020

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
@aduh95
Copy link
Contributor

aduh95 commented Jan 16, 2020

This has been fixed by #27558, and it has landed in v13.0.0. Because it is a breaking change, it has not been backported to the LTS lines. However you can change the default behaviour using a flag on v12 (#27704) and v10 (#27939).

Duplicate of #27556.

aduh95 added a commit to aduh95/node that referenced this issue Jan 31, 2020
Prior to Node.js v13, http[2s] have a specific default timeout value
which should not be confused with net.Socket default timeout.

Fixes: nodejs#31378
Fixes: nodejs#27556
Refs: nodejs#27704
@juanarbol
Copy link
Member

@natlibfi-arlehiko thank you for opening the issue, I'm going to close this because it is now fixed on v13x.x and v14.x, and you can change this behavior in v12 by using a flag (thanks @aduh95 for the support, amazing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants