Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9927335

Browse filesBrowse files
tadjik1aduh95
authored andcommitted
tls: forward keepAlive, keepAliveInitialDelay, noDelay to socket
`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: #62003 PR-URL: #62004 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
1 parent 774d0be commit 9927335
Copy full SHA for 9927335

4 files changed

+77-3Lines changed: 77 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/net.js‎

Copy file name to clipboardExpand all lines: lib/internal/net.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ function isLoopback(host) {
100100

101101
module.exports = {
102102
kReinitializeHandle: Symbol('kReinitializeHandle'),
103+
kSetNoDelay: Symbol('kSetNoDelay'),
104+
kSetKeepAlive: Symbol('kSetKeepAlive'),
105+
kSetKeepAliveInitialDelay: Symbol('kSetKeepAliveInitialDelay'),
103106
isIP,
104107
isIPv4,
105108
isIPv6,
Collapse file

‎lib/internal/tls/wrap.js‎

Copy file name to clipboardExpand all lines: lib/internal/tls/wrap.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ function TLSSocket(socket, opts) {
595595
highWaterMark: tlsOptions.highWaterMark,
596596
onread: !socket ? tlsOptions.onread : null,
597597
signal: tlsOptions.signal,
598+
noDelay: tlsOptions.noDelay,
599+
keepAlive: tlsOptions.keepAlive,
600+
keepAliveInitialDelay: tlsOptions.keepAliveInitialDelay,
598601
});
599602

600603
// Proxy for API compatibility
@@ -1752,6 +1755,9 @@ exports.connect = function connect(...args) {
17521755
highWaterMark: options.highWaterMark,
17531756
onread: options.onread,
17541757
signal: options.signal,
1758+
noDelay: options.noDelay,
1759+
keepAlive: options.keepAlive,
1760+
keepAliveInitialDelay: options.keepAliveInitialDelay,
17551761
});
17561762

17571763
// rejectUnauthorized property can be explicitly defined as `undefined`
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ let debug = require('internal/util/debuglog').debuglog('net', (fn) => {
4848
});
4949
const {
5050
kReinitializeHandle,
51+
kSetNoDelay,
52+
kSetKeepAlive,
53+
kSetKeepAliveInitialDelay,
5154
isIP,
5255
isIPv4,
5356
isIPv6,
@@ -356,9 +359,6 @@ function closeSocketHandle(self, isException, isCleanupPending = false) {
356359

357360
const kBytesRead = Symbol('kBytesRead');
358361
const kBytesWritten = Symbol('kBytesWritten');
359-
const kSetNoDelay = Symbol('kSetNoDelay');
360-
const kSetKeepAlive = Symbol('kSetKeepAlive');
361-
const kSetKeepAliveInitialDelay = Symbol('kSetKeepAliveInitialDelay');
362362
const kSetTOS = Symbol('kSetTOS');
363363

364364
function Socket(options) {
Collapse file
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
4+
const common = require('../common');
5+
6+
// This test verifies that tls.connect() forwards keepAlive,
7+
// keepAliveInitialDelay, and noDelay options to the underlying socket.
8+
9+
if (!common.hasCrypto)
10+
common.skip('missing crypto');
11+
12+
const assert = require('assert');
13+
const tls = require('tls');
14+
const fixtures = require('../common/fixtures');
15+
const {
16+
kSetNoDelay,
17+
kSetKeepAlive,
18+
kSetKeepAliveInitialDelay,
19+
} = require('internal/net');
20+
21+
const key = fixtures.readKey('agent1-key.pem');
22+
const cert = fixtures.readKey('agent1-cert.pem');
23+
24+
// Test: keepAlive, keepAliveInitialDelay, and noDelay
25+
{
26+
const server = tls.createServer({ key, cert }, (socket) => {
27+
socket.end();
28+
});
29+
30+
server.listen(0, common.mustCall(() => {
31+
const socket = tls.connect({
32+
port: server.address().port,
33+
rejectUnauthorized: false,
34+
keepAlive: true,
35+
keepAliveInitialDelay: 1000,
36+
noDelay: true,
37+
}, common.mustCall(() => {
38+
assert.strictEqual(socket[kSetKeepAlive], true);
39+
assert.strictEqual(socket[kSetKeepAliveInitialDelay], 1);
40+
assert.strictEqual(socket[kSetNoDelay], true);
41+
socket.destroy();
42+
server.close();
43+
}));
44+
}));
45+
}
46+
47+
// Test: defaults (options not set)
48+
{
49+
const server = tls.createServer({ key, cert }, (socket) => {
50+
socket.end();
51+
});
52+
53+
server.listen(0, common.mustCall(() => {
54+
const socket = tls.connect({
55+
port: server.address().port,
56+
rejectUnauthorized: false,
57+
}, common.mustCall(() => {
58+
assert.strictEqual(socket[kSetKeepAlive], false);
59+
assert.strictEqual(socket[kSetKeepAliveInitialDelay], 0);
60+
assert.strictEqual(socket[kSetNoDelay], false);
61+
socket.destroy();
62+
server.close();
63+
}));
64+
}));
65+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.