diff --git a/lib/net.js b/lib/net.js index d4305639cc5adf..6f6930aaf8de7d 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1659,12 +1659,11 @@ function onconnection(err, clientHandle) { writable: true }); - if (self.noDelay && handle.setNoDelay) { - handle.setNoDelay(true); + if (self.noDelay && clientHandle.setNoDelay) { + clientHandle.setNoDelay(true); } - - if (self.keepAlive && self.setKeepAlive) { - handle.setKeepAlive(true, handle.keepAliveInitialDelay); + if (self.keepAlive && clientHandle.setKeepAlive) { + clientHandle.setKeepAlive(true, self.keepAliveInitialDelay); } self._connections++; diff --git a/test/parallel/test-net-server-keepalive.js b/test/parallel/test-net-server-keepalive.js new file mode 100644 index 00000000000000..384787d22bb69c --- /dev/null +++ b/test/parallel/test-net-server-keepalive.js @@ -0,0 +1,25 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); + +const server = net.createServer({ + keepAlive: true, + keepAliveInitialDelay: 1000 +}, common.mustCall((socket) => { + socket.destroy(); + server.close(); +})).listen(0, common.mustCall(() => { + net.connect(server.address().port); +})); + +const onconnection = server._handle.onconnection; +server._handle.onconnection = common.mustCall((err, clientHandle) => { + const setKeepAlive = clientHandle.setKeepAlive; + clientHandle.setKeepAlive = common.mustCall((enable, initialDelayMsecs) => { + assert.strictEqual(enable, server.keepAlive); + assert.strictEqual(initialDelayMsecs, server.keepAliveInitialDelay); + setKeepAlive.call(clientHandle, enable, initialDelayMsecs); + }); + onconnection.call(server._handle, err, clientHandle); +}); diff --git a/test/parallel/test-net-server-nodelay.js b/test/parallel/test-net-server-nodelay.js new file mode 100644 index 00000000000000..f5ee77f71c5383 --- /dev/null +++ b/test/parallel/test-net-server-nodelay.js @@ -0,0 +1,23 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); + +const server = net.createServer({ + noDelay: true +}, common.mustCall((socket) => { + socket.destroy(); + server.close(); +})).listen(0, common.mustCall(() => { + net.connect(server.address().port); +})); + +const onconnection = server._handle.onconnection; +server._handle.onconnection = common.mustCall((err, clientHandle) => { + const setNoDelay = clientHandle.setNoDelay; + clientHandle.setNoDelay = common.mustCall((enable) => { + assert.strictEqual(enable, server.noDelay); + setNoDelay.call(clientHandle, enable); + }); + onconnection.call(server._handle, err, clientHandle); +});