Skip to content

Commit

Permalink
doc,test: add server.timeout property to http2 public API
Browse files Browse the repository at this point in the history
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 <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
puzpuzpuz authored and MylesBorins committed Mar 11, 2020
1 parent e83671c commit 77e5b50
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 16 deletions.
42 changes: 40 additions & 2 deletions doc/api/http2.md
Expand Up @@ -1797,9 +1797,28 @@ on the `Http2Server` after `msecs` milliseconds.

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

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

#### `server.timeout`
<!-- YAML
added: v8.4.0
changes:
- version: v13.0.0
pr-url: https://github.com/nodejs/node/pull/27558
description: The default timeout changed from 120s to 0 (no timeout).
-->

* {number} Timeout in milliseconds. **Default:** 0 (no timeout)

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

A value of `0` will disable the timeout behavior on incoming connections.

The socket timeout logic is set up on connection, so changing this
value only affects new connections to the server, not any existing connections.

### Class: `Http2SecureServer`
<!-- YAML
added: v8.4.0
Expand Down Expand Up @@ -1943,9 +1962,28 @@ on the `Http2SecureServer` after `msecs` milliseconds.

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

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

#### `server.timeout`
<!-- YAML
added: v8.4.0
changes:
- version: v13.0.0
pr-url: https://github.com/nodejs/node/pull/27558
description: The default timeout changed from 120s to 0 (no timeout).
-->

* {number} Timeout in milliseconds. **Default:** 0 (no timeout)

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

A value of `0` will disable the timeout behavior on incoming connections.

The socket timeout logic is set up on connection, so changing this
value only affects new connections to the server, not any existing connections.

### `http2.createServer(options[, onRequestHandler])`
<!-- YAML
added: v8.4.0
Expand Down
34 changes: 20 additions & 14 deletions test/parallel/test-http2-server-timeout.js
Expand Up @@ -5,21 +5,27 @@ if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');

const server = http2.createServer();
server.setTimeout(common.platformTimeout(50));
function testServerTimeout(setTimeoutFn) {
const server = http2.createServer();
setTimeoutFn(server);

const onServerTimeout = common.mustCall((session) => {
session.close();
});
const onServerTimeout = common.mustCall((session) => {
session.close();
});

server.on('stream', common.mustNotCall());
server.once('timeout', onServerTimeout);
server.on('stream', common.mustNotCall());
server.once('timeout', onServerTimeout);

server.listen(0, common.mustCall(() => {
const url = `http://localhost:${server.address().port}`;
const client = http2.connect(url);
client.on('close', common.mustCall(() => {
const client2 = http2.connect(url);
client2.on('close', common.mustCall(() => server.close()));
server.listen(0, common.mustCall(() => {
const url = `http://localhost:${server.address().port}`;
const client = http2.connect(url);
client.on('close', common.mustCall(() => {
const client2 = http2.connect(url);
client2.on('close', common.mustCall(() => server.close()));
}));
}));
}));
}

const timeout = common.platformTimeout(50);
testServerTimeout((server) => server.setTimeout(timeout));
testServerTimeout((server) => server.timeout = timeout);

0 comments on commit 77e5b50

Please sign in to comment.