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

Http2 Timeouts #168

Merged
merged 7 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

### v0.5.5 -- 2023-03-20

Notable changes:

* Tweaked timeouts for HTTP2 connections, in the hopes of working around an
apparent HTTP2-related memory leak in the Node core library. This is
[issue #42710](https://github.com/nodejs/node/issues/42710) in the Node repo.

### v0.5.4 -- 2023-03-10

Notable changes:
Expand Down
2 changes: 1 addition & 1 deletion src/main-lactoserv/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@this/main-lactoserv",
"version": "0.5.4",
"version": "0.5.5",
"type": "module",
"private": true,
"license": "Apache-2.0",
Expand Down
40 changes: 35 additions & 5 deletions src/network-protocol/private/Http2Wrangler.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,28 @@ export class Http2Wrangler extends TcpWrangler {
};

// Express needs to be wrapped in order for it to use HTTP2.
this.#application = http2ExpressBridge(express);
this.#protocolServer = http2.createSecureServer(serverOptions);

this.#application = http2ExpressBridge(express);
this.#application.use('/', (req, res, next) => this.#tweakResponse(req, res, next));

this.#protocolServer = http2.createSecureServer(serverOptions);
this.#protocolServer.on('session', (session) => this.#addSession(session));

// Explicitly set both an overall server timeout _and_ the server's default
// socket timeout, as doing these _might_ mitigate a memory leak as noted in
// <https://github.com/nodejs/node/issues/42710>. As of this writing, there
// _is_ a memory leak of some sort in this project, and the working
// hypothesis is that setting this timeout will suffice as a fix /
// workaround (depending on one's perspective). That said, the discussion
// in the bug in question is ambiguous -- does just one of these need to be
// set? -- and so maybe this is now overkill (or whatever).
this.#protocolServer.setTimeout(Http2Wrangler.#SERVER_TIMEOUT_MSEC);
this.#protocolServer.timeout = Http2Wrangler.#SOCKET_TIMEOUT_MSEC;

// TODO: Either remove this entirely, if it turns out that the server
// timeout is useless (for us), or add something useful here.
this.#protocolServer.on('timeout', () => {
this.#logger?.serverTimeout();
});
}

/** @override */
Expand Down Expand Up @@ -232,9 +249,22 @@ export class Http2Wrangler extends TcpWrangler {
*/
static #STOP_GRACE_PERIOD_MSEC = 250;

/**
* @type {number} How long in msec to wait before considering a server
* "timed out." TODO: Figure out if this has any real meaning if one isn't
* actually doing anything when timeout occurs.
*/
static #SERVER_TIMEOUT_MSEC = 5 * 60 * 1000; // Five minutes.

/**
* @type {number} How long in msec to wait for a session to have activity
* before telling it to close.
* before considering it "timed out" and telling it to close.
*/
static #SESSION_TIMEOUT_MSEC = 2 * 60 * 1000; // Two minutes.

/**
* @type {number} How long in msec to wait before considering a socket
* "timed out."
*/
static #SESSION_TIMEOUT_MSEC = 5 * 60 * 1000; // Five minutes.
static #SOCKET_TIMEOUT_MSEC = 1 * 60 * 1000; // One minute.
}