Skip to content

Commit 68ad950

Browse files
committed
test: add regression test for setKeepAlive handle errors
1 parent 302ff72 commit 68ad950

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const net = require('net');
6+
7+
// Regression: setKeepAlive() silently ignored errors returned by the
8+
// underlying handle (https://github.com/nodejs/node/issues/65529).
9+
// It should throw like setTypeOfService() does, instead of reporting
10+
// success when the operation failed.
11+
if (common.isWindows) {
12+
common.skip('keep-alive errors are treated as best-effort on Windows');
13+
} else {
14+
const server = net.createServer(common.mustCall((socket) => {
15+
socket.end();
16+
}));
17+
18+
server.listen(0, common.mustCall(() => {
19+
const client = net.connect(server.address().port, common.mustCall(() => {
20+
// Make the handle report an error (EINVAL) for the keep-alive call.
21+
const originalSetKeepAlive = client._handle.setKeepAlive;
22+
client._handle.setKeepAlive = () => -22; // UV_EINVAL
23+
try {
24+
assert.throws(
25+
() => client.setKeepAlive(true, 1000),
26+
(err) => {
27+
assert.strictEqual(err.code, 'EINVAL');
28+
assert.strictEqual(err.syscall, 'setKeepAlive');
29+
return true;
30+
},
31+
);
32+
} finally {
33+
client._handle.setKeepAlive = originalSetKeepAlive;
34+
}
35+
client.end();
36+
server.close();
37+
}));
38+
}));
39+
}

0 commit comments

Comments
 (0)