mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 06:38:13 +00:00

Wait for the data to be received by the socket before creating the clean-up timer. This way, a possible (though unlikely) `ECONNRESET` error can be avoided. PR-URL: https://github.com/nodejs/node/pull/6166 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
32 lines
725 B
JavaScript
32 lines
725 B
JavaScript
'use strict';
|
|
// This example sets a timeout then immediately attempts to disable the timeout
|
|
// https://github.com/joyent/node/pull/2245
|
|
|
|
const common = require('../common');
|
|
const net = require('net');
|
|
const assert = require('assert');
|
|
|
|
const T = 100;
|
|
|
|
const server = net.createServer(common.mustCall((c) => {
|
|
c.write('hello');
|
|
}));
|
|
|
|
server.listen(common.PORT);
|
|
|
|
const socket = net.createConnection(common.PORT, 'localhost');
|
|
|
|
const s = socket.setTimeout(T, () => {
|
|
common.fail('Socket timeout event is not expected to fire');
|
|
});
|
|
assert.ok(s instanceof net.Socket);
|
|
|
|
socket.on('data', common.mustCall(() => {
|
|
setTimeout(function() {
|
|
socket.destroy();
|
|
server.close();
|
|
}, T * 2);
|
|
}));
|
|
|
|
socket.setTimeout(0);
|