Skip to content

Commit c30ef3c

Browse files
committed
http, http2: remove default server timeout
Timing out and closing the socket after two minutes have elapsed is surprising and problematic for users. This behavior was specific to Node.js, and doesn't seem to be common in other language runtimes. Fixes: #27556 PR-URL: #27558 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent e582d11 commit c30ef3c

File tree

7 files changed

+28
-17
lines changed

7 files changed

+28
-17
lines changed

doc/api/http.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,13 @@ Limits maximum incoming headers count. If set to 0, no limit will be applied.
10131013
### server.setTimeout([msecs][, callback])
10141014
<!-- YAML
10151015
added: v0.9.12
1016+
changes:
1017+
- version: REPLACEME
1018+
pr-url: https://github.com/nodejs/node/pull/27558
1019+
description: The default timeout changed from 120s to 0 (no timeout).
10161020
-->
10171021

1018-
* `msecs` {number} **Default:** `120000` (2 minutes)
1022+
* `msecs` {number} **Default:** 0 (no timeout)
10191023
* `callback` {Function}
10201024
* Returns: {http.Server}
10211025

@@ -1026,16 +1030,20 @@ occurs.
10261030
If there is a `'timeout'` event listener on the Server object, then it
10271031
will be called with the timed-out socket as an argument.
10281032

1029-
By default, the Server's timeout value is 2 minutes, and sockets are
1030-
destroyed automatically if they time out. However, if a callback is assigned
1031-
to the Server's `'timeout'` event, timeouts must be handled explicitly.
1033+
By default, the Server does not timeout sockets. However, if a callback
1034+
is assigned to the Server's `'timeout'` event, timeouts must be handled
1035+
explicitly.
10321036

10331037
### server.timeout
10341038
<!-- YAML
10351039
added: v0.9.12
1040+
changes:
1041+
- version: REPLACEME
1042+
pr-url: https://github.com/nodejs/node/pull/27558
1043+
description: The default timeout changed from 120s to 0 (no timeout).
10361044
-->
10371045

1038-
* {number} Timeout in milliseconds. **Default:** `120000` (2 minutes).
1046+
* {number} Timeout in milliseconds. **Default:** 0 (no timeout)
10391047

10401048
The number of milliseconds of inactivity before a socket is presumed
10411049
to have timed out.

doc/api/http2.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -1722,11 +1722,15 @@ server.on('stream', (stream, headers, flags) => {
17221722
#### Event: 'timeout'
17231723
<!-- YAML
17241724
added: v8.4.0
1725+
changes:
1726+
- version: REPLACEME
1727+
pr-url: https://github.com/nodejs/node/pull/27558
1728+
description: The default timeout changed from 120s to 0 (no timeout).
17251729
-->
17261730

17271731
The `'timeout'` event is emitted when there is no activity on the Server for
17281732
a given number of milliseconds set using `http2server.setTimeout()`.
1729-
**Default:** 2 minutes.
1733+
**Default:** 0 (no timeout)
17301734

17311735
#### server.close([callback])
17321736
<!-- YAML
@@ -1743,9 +1747,13 @@ consider also using [`http2session.close()`] on active sessions.
17431747
#### server.setTimeout([msecs][, callback])
17441748
<!-- YAML
17451749
added: v8.4.0
1750+
changes:
1751+
- version: REPLACEME
1752+
pr-url: https://github.com/nodejs/node/pull/27558
1753+
description: The default timeout changed from 120s to 0 (no timeout).
17461754
-->
17471755

1748-
* `msecs` {number} **Default:** `120000` (2 minutes)
1756+
* `msecs` {number} **Default:** 0 (no timeout)
17491757
* `callback` {Function}
17501758
* Returns: {Http2Server}
17511759

lib/_http_server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function Server(options, requestListener) {
315315

316316
this.on('connection', connectionListener);
317317

318-
this.timeout = 2 * 60 * 1000;
318+
this.timeout = 0;
319319
this.keepAliveTimeout = 5000;
320320
this.maxHeadersCount = null;
321321
this.headersTimeout = 40 * 1000; // 40 seconds

lib/https.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function Server(opts, requestListener) {
7171
conn.destroy(err);
7272
});
7373

74-
this.timeout = 2 * 60 * 1000;
74+
this.timeout = 0;
7575
this.keepAliveTimeout = 5000;
7676
this.maxHeadersCount = null;
7777
this.headersTimeout = 40 * 1000; // 40 seconds

lib/internal/http2/core.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ const kState = Symbol('state');
171171
const kType = Symbol('type');
172172
const kWriteGeneric = Symbol('write-generic');
173173

174-
const kDefaultSocketTimeout = 2 * 60 * 1000;
175-
176174
const {
177175
paddingBuffer,
178176
PADDING_BUF_FRAME_LENGTH,
@@ -2680,7 +2678,7 @@ class Http2SecureServer extends TLSServer {
26802678
options = initializeTLSOptions(options);
26812679
super(options, connectionListener);
26822680
this[kOptions] = options;
2683-
this.timeout = kDefaultSocketTimeout;
2681+
this.timeout = 0;
26842682
this.on('newListener', setupCompat);
26852683
if (typeof requestListener === 'function')
26862684
this.on('request', requestListener);
@@ -2702,7 +2700,7 @@ class Http2Server extends NETServer {
27022700
constructor(options, requestListener) {
27032701
super(connectionListener);
27042702
this[kOptions] = initializeOptions(options);
2705-
this.timeout = kDefaultSocketTimeout;
2703+
this.timeout = 0;
27062704
this.on('newListener', setupCompat);
27072705
if (typeof requestListener === 'function')
27082706
this.on('request', requestListener);

test/async-hooks/test-graph.http.js

-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ process.on('exit', function() {
4343
{ type: 'HTTPINCOMINGMESSAGE',
4444
id: 'httpincomingmessage:1',
4545
triggerAsyncId: 'tcp:2' },
46-
{ type: 'Timeout',
47-
id: 'timeout:2',
48-
triggerAsyncId: 'tcp:2' },
4946
{ type: 'SHUTDOWNWRAP',
5047
id: 'shutdown:1',
5148
triggerAsyncId: 'tcp:2' } ]

test/parallel/test-child-process-http-socket-leak.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ server.listen(0, common.mustCall(() => {
4646
}, common.mustCall((res) => {
4747
res.on('data', () => {});
4848
res.on('end', common.mustCall(() => {
49-
assert.strictEqual(socket[kTimeout]._idleTimeout, -1);
49+
assert.strictEqual(socket[kTimeout], null);
5050
assert.strictEqual(socket.parser, null);
5151
assert.strictEqual(socket._httpMessage, null);
5252
}));

0 commit comments

Comments
 (0)