Skip to content

Commit 77e5b50

Browse files
puzpuzpuzMylesBorins
authored andcommittedMar 11, 2020
doc,test: add server.timeout property to http2 public API
Both http and https modules have server.timeout property in public API. This commit adds documentation section and test for server.timeout in http2 module, so it becomes consistent with http and https. Also improves description of callback argument in documentation for server.setTimeout(). PR-URL: #31693 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent e83671c commit 77e5b50

File tree

2 files changed

+60
-16
lines changed

2 files changed

+60
-16
lines changed
 

‎doc/api/http2.md

+40-2
Original file line numberDiff line numberDiff line change
@@ -1797,9 +1797,28 @@ on the `Http2Server` after `msecs` milliseconds.
17971797

17981798
The given callback is registered as a listener on the `'timeout'` event.
17991799

1800-
In case of no callback function were assigned, a new `ERR_INVALID_CALLBACK`
1800+
In case if `callback` is not a function, a new `ERR_INVALID_CALLBACK`
18011801
error will be thrown.
18021802

1803+
#### `server.timeout`
1804+
<!-- YAML
1805+
added: v8.4.0
1806+
changes:
1807+
- version: v13.0.0
1808+
pr-url: https://github.com/nodejs/node/pull/27558
1809+
description: The default timeout changed from 120s to 0 (no timeout).
1810+
-->
1811+
1812+
* {number} Timeout in milliseconds. **Default:** 0 (no timeout)
1813+
1814+
The number of milliseconds of inactivity before a socket is presumed
1815+
to have timed out.
1816+
1817+
A value of `0` will disable the timeout behavior on incoming connections.
1818+
1819+
The socket timeout logic is set up on connection, so changing this
1820+
value only affects new connections to the server, not any existing connections.
1821+
18031822
### Class: `Http2SecureServer`
18041823
<!-- YAML
18051824
added: v8.4.0
@@ -1943,9 +1962,28 @@ on the `Http2SecureServer` after `msecs` milliseconds.
19431962

19441963
The given callback is registered as a listener on the `'timeout'` event.
19451964

1946-
In case of no callback function were assigned, a new `ERR_INVALID_CALLBACK`
1965+
In case if `callback` is not a function, a new `ERR_INVALID_CALLBACK`
19471966
error will be thrown.
19481967

1968+
#### `server.timeout`
1969+
<!-- YAML
1970+
added: v8.4.0
1971+
changes:
1972+
- version: v13.0.0
1973+
pr-url: https://github.com/nodejs/node/pull/27558
1974+
description: The default timeout changed from 120s to 0 (no timeout).
1975+
-->
1976+
1977+
* {number} Timeout in milliseconds. **Default:** 0 (no timeout)
1978+
1979+
The number of milliseconds of inactivity before a socket is presumed
1980+
to have timed out.
1981+
1982+
A value of `0` will disable the timeout behavior on incoming connections.
1983+
1984+
The socket timeout logic is set up on connection, so changing this
1985+
value only affects new connections to the server, not any existing connections.
1986+
19491987
### `http2.createServer(options[, onRequestHandler])`
19501988
<!-- YAML
19511989
added: v8.4.0

‎test/parallel/test-http2-server-timeout.js

+20-14
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@ if (!common.hasCrypto)
55
common.skip('missing crypto');
66
const http2 = require('http2');
77

8-
const server = http2.createServer();
9-
server.setTimeout(common.platformTimeout(50));
8+
function testServerTimeout(setTimeoutFn) {
9+
const server = http2.createServer();
10+
setTimeoutFn(server);
1011

11-
const onServerTimeout = common.mustCall((session) => {
12-
session.close();
13-
});
12+
const onServerTimeout = common.mustCall((session) => {
13+
session.close();
14+
});
1415

15-
server.on('stream', common.mustNotCall());
16-
server.once('timeout', onServerTimeout);
16+
server.on('stream', common.mustNotCall());
17+
server.once('timeout', onServerTimeout);
1718

18-
server.listen(0, common.mustCall(() => {
19-
const url = `http://localhost:${server.address().port}`;
20-
const client = http2.connect(url);
21-
client.on('close', common.mustCall(() => {
22-
const client2 = http2.connect(url);
23-
client2.on('close', common.mustCall(() => server.close()));
19+
server.listen(0, common.mustCall(() => {
20+
const url = `http://localhost:${server.address().port}`;
21+
const client = http2.connect(url);
22+
client.on('close', common.mustCall(() => {
23+
const client2 = http2.connect(url);
24+
client2.on('close', common.mustCall(() => server.close()));
25+
}));
2426
}));
25-
}));
27+
}
28+
29+
const timeout = common.platformTimeout(50);
30+
testServerTimeout((server) => server.setTimeout(timeout));
31+
testServerTimeout((server) => server.timeout = timeout);

0 commit comments

Comments
 (0)
Please sign in to comment.