See https://github.com/nodejs/node/pull/30839
_writeGeneric waits for 'connect' https://github.com/nodejs/node/blob/cf5ce2c9e1aab5eadbae107c697fdd11c6fb93a9/lib/net.js#L759 which might never be emitted due to https://github.com/nodejs/node/blob/cf5ce2c9e1aab5eadbae107c697fdd11c6fb93a9/lib/net.js#L1106-L1108
I believe this will fail:
const socket = createSocketBeforeConnect();
socket.write('asd', common.mustCall());
socket.destroy();
This is fixed
If the expectation is that callback is called this is not fixed.
const assert = require('assert');
const net = require('net');
const socket = new net.Socket();
socket.connect({
port: 80,
host: 'example.com',
lookup() {}
});
assert(socket.connecting);
let called = false;
socket.write('foo', function() {
called = true;
});
socket.destroy();
process.on('exit', function() {
assert(called);
});
Yea, we should add a test for that.
This seems related to the whole constructing state which in this case never gets resolved, i.e. _write never finishes https://github.com/nodejs/node/blob/master/lib/net.js#L763. I can dig into this once/if https://github.com/nodejs/node/pull/29656 lands.
yes, _writeGeneric() is never called as 'connect' is never emitted.
pending resolution to discussion in https://github.com/nodejs/node/pull/31179
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const socket = new net.Socket();
socket.connect({
port: 80,
host: 'example.com',
lookup() {}
});
assert(socket.connecting);
socket.write('foo', common.mustCall());
socket.destroy();
This requires https://github.com/nodejs/node/pull/29656 in order to be fully resolved.