From 6a3d358ca4111c8b43070d5e838d599bdff48d55 Mon Sep 17 00:00:00 2001 From: Sergey Zelenov Date: Sat, 28 Feb 2026 12:22:35 +0100 Subject: [PATCH 1/3] tls: forward keepAlive, keepAliveInitialDelay, noDelay to socket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `tls.connect()` silently ignores `keepAlive`, `keepAliveInitialDelay`, and `noDelay` options. The documentation states it accepts any `socket.connect()` option, and `net.createConnection()` with the same options works correctly. Forward the options through both code paths so `net.Socket`'s constructor stores them on the internal symbols (`kSetNoDelay`, `kSetKeepAlive`, `kSetKeepAliveInitialDelay`), which `afterConnect()` then applies to the handle. Fixes: https://github.com/nodejs/node/issues/62003 PR-URL: https://github.com/nodejs/node/pull/62004 Reviewed-By: Matteo Collina Reviewed-By: Anna Henningsen Reviewed-By: René --- lib/internal/net.js | 3 + lib/internal/tls/wrap.js | 6 ++ lib/net.js | 6 +- .../test-tls-connect-keepalive-nodelay.js | 65 +++++++++++++++++++ 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-tls-connect-keepalive-nodelay.js diff --git a/lib/internal/net.js b/lib/internal/net.js index d380d8a41982e2..80de67791512e4 100644 --- a/lib/internal/net.js +++ b/lib/internal/net.js @@ -100,6 +100,9 @@ function isLoopback(host) { module.exports = { kReinitializeHandle: Symbol('kReinitializeHandle'), + kSetNoDelay: Symbol('kSetNoDelay'), + kSetKeepAlive: Symbol('kSetKeepAlive'), + kSetKeepAliveInitialDelay: Symbol('kSetKeepAliveInitialDelay'), isIP, isIPv4, isIPv6, diff --git a/lib/internal/tls/wrap.js b/lib/internal/tls/wrap.js index 7a1752649c4277..308180d483908d 100644 --- a/lib/internal/tls/wrap.js +++ b/lib/internal/tls/wrap.js @@ -590,6 +590,9 @@ function TLSSocket(socket, opts) { highWaterMark: tlsOptions.highWaterMark, onread: !socket ? tlsOptions.onread : null, signal: tlsOptions.signal, + noDelay: tlsOptions.noDelay, + keepAlive: tlsOptions.keepAlive, + keepAliveInitialDelay: tlsOptions.keepAliveInitialDelay, }); // Proxy for API compatibility @@ -1755,6 +1758,9 @@ exports.connect = function connect(...args) { highWaterMark: options.highWaterMark, onread: options.onread, signal: options.signal, + noDelay: options.noDelay, + keepAlive: options.keepAlive, + keepAliveInitialDelay: options.keepAliveInitialDelay, }); // rejectUnauthorized property can be explicitly defined as `undefined` diff --git a/lib/net.js b/lib/net.js index e22ef4bfc4bff0..efd2029fb67ddd 100644 --- a/lib/net.js +++ b/lib/net.js @@ -48,6 +48,9 @@ let debug = require('internal/util/debuglog').debuglog('net', (fn) => { }); const { kReinitializeHandle, + kSetNoDelay, + kSetKeepAlive, + kSetKeepAliveInitialDelay, isIP, isIPv4, isIPv6, @@ -356,9 +359,6 @@ function closeSocketHandle(self, isException, isCleanupPending = false) { const kBytesRead = Symbol('kBytesRead'); const kBytesWritten = Symbol('kBytesWritten'); -const kSetNoDelay = Symbol('kSetNoDelay'); -const kSetKeepAlive = Symbol('kSetKeepAlive'); -const kSetKeepAliveInitialDelay = Symbol('kSetKeepAliveInitialDelay'); const kSetTOS = Symbol('kSetTOS'); function Socket(options) { diff --git a/test/parallel/test-tls-connect-keepalive-nodelay.js b/test/parallel/test-tls-connect-keepalive-nodelay.js new file mode 100644 index 00000000000000..81eaafabc64a6f --- /dev/null +++ b/test/parallel/test-tls-connect-keepalive-nodelay.js @@ -0,0 +1,65 @@ +// Flags: --expose-internals +'use strict'; + +const common = require('../common'); + +// This test verifies that tls.connect() forwards keepAlive, +// keepAliveInitialDelay, and noDelay options to the underlying socket. + +if (!common.hasCrypto) + common.skip('missing crypto'); + +const assert = require('assert'); +const tls = require('tls'); +const fixtures = require('../common/fixtures'); +const { + kSetNoDelay, + kSetKeepAlive, + kSetKeepAliveInitialDelay, +} = require('internal/net'); + +const key = fixtures.readKey('agent1-key.pem'); +const cert = fixtures.readKey('agent1-cert.pem'); + +// Test: keepAlive, keepAliveInitialDelay, and noDelay +{ + const server = tls.createServer({ key, cert }, (socket) => { + socket.end(); + }); + + server.listen(0, common.mustCall(() => { + const socket = tls.connect({ + port: server.address().port, + rejectUnauthorized: false, + keepAlive: true, + keepAliveInitialDelay: 1000, + noDelay: true, + }, common.mustCall(() => { + assert.strictEqual(socket[kSetKeepAlive], true); + assert.strictEqual(socket[kSetKeepAliveInitialDelay], 1); + assert.strictEqual(socket[kSetNoDelay], true); + socket.destroy(); + server.close(); + })); + })); +} + +// Test: defaults (options not set) +{ + const server = tls.createServer({ key, cert }, (socket) => { + socket.end(); + }); + + server.listen(0, common.mustCall(() => { + const socket = tls.connect({ + port: server.address().port, + rejectUnauthorized: false, + }, common.mustCall(() => { + assert.strictEqual(socket[kSetKeepAlive], false); + assert.strictEqual(socket[kSetKeepAliveInitialDelay], 0); + assert.strictEqual(socket[kSetNoDelay], false); + socket.destroy(); + server.close(); + })); + })); +} From 27261b9391d755de208814dfae3f8f0923dc07b4 Mon Sep 17 00:00:00 2001 From: Mike McCready <66998419+MikeMcC399@users.noreply.github.com> Date: Sat, 28 Feb 2026 13:26:00 +0100 Subject: [PATCH 2/3] doc: update DEP0040 (punycode) to application type deprecation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/61916 Reviewed-By: René --- doc/api/deprecations.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 7e6347927962b2..186cb2381935cc 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -932,6 +932,11 @@ The [`require.extensions`][] property is deprecated. -Type: Runtime +Type: Application (non-`node_modules` code only) The [`punycode`][] module is deprecated. Please use a userland alternative instead. From 6964b539806e3b2103dd6b65572287b8a615f5d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Wed, 25 Feb 2026 21:29:41 +0000 Subject: [PATCH 3/3] doc: fix module.stripTypeScriptTypes indentation PR-URL: https://github.com/nodejs/node/pull/61992 Reviewed-By: Chengzhong Wu Reviewed-By: Jacob Smith Reviewed-By: Marco Ippolito Reviewed-By: Harshitha K P Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca --- doc/api/module.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/api/module.md b/doc/api/module.md index cad96d23476c64..6ed09d996823c0 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -259,12 +259,13 @@ changes: * `'strip'` Only strip type annotations without performing the transformation of TypeScript features. * `sourceUrl` {string} Specifies the source url used in the source map. * Returns: {string} The code with type annotations stripped. - `module.stripTypeScriptTypes()` removes type annotations from TypeScript code. It - can be used to strip type annotations from TypeScript code before running it - with `vm.runInContext()` or `vm.compileFunction()`. - By default, it will throw an error if the code contains TypeScript features - that require transformation such as `Enums`, - see [type-stripping][] for more information. + +`module.stripTypeScriptTypes()` removes type annotations from TypeScript code. It +can be used to strip type annotations from TypeScript code before running it +with `vm.runInContext()` or `vm.compileFunction()`. + +By default, it will throw an error if the code contains TypeScript features +that require transformation, such as `enum`s. See [type-stripping][] for more information. _WARNING_: The output of this function should not be considered stable across Node.js versions, due to changes in the TypeScript parser.