mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
a03529d828
Make sure that when calling `write()` on a connecting socket, the callback is called if the socket is destroyed before the connection is established. Fixes: https://github.com/nodejs/node/issues/30841 PR-URL: https://github.com/nodejs/node/pull/45922 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
27 lines
525 B
JavaScript
27 lines
525 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const net = require('net');
|
|
|
|
const server = net.createServer();
|
|
server.listen(0, common.mustCall(() => {
|
|
const socket = new net.Socket();
|
|
|
|
socket.on('connect', common.mustNotCall());
|
|
|
|
socket.connect({
|
|
port: server.address().port,
|
|
});
|
|
|
|
assert(socket.connecting);
|
|
|
|
socket.write('foo', common.expectsError({
|
|
code: 'ERR_SOCKET_CLOSED_BEFORE_CONNECTION',
|
|
name: 'Error'
|
|
}));
|
|
|
|
socket.destroy();
|
|
server.close();
|
|
}));
|