Description
This came up during many attempts at addressing flakiness in test-net-error-twice.js
. The flakiness is resolved now, but the underlying issue remains. Not entirely sure this is a bug but it's strange enough I think to warrant an explanation. (And it's probably a bug.)
This has been observed only on systems that meet the following criteria:
- Windows 2012r2
- single processor
The following code will throw an AssertionError
because the error
callback is never triggered. If you comment out the useless assignment of console
to foo
, though, then the code works. If you uncomment the console.log()
in the connection callback (or otherwise put a console.log()
in one of many but not all places in the file), then the code works.
Why is this? Windows bug? libuv bug? Not a bug at all? (OK, if that's the case, then fine, it's not a bug, but seriously, why does this happen? Why should assigning console
to a variable affect this at all?)
'use strict';
var foo = console; // Comment out this line and the callback fires as expected.
const assert = require('assert');
const net = require('net');
const buf = new Buffer(10 * 1024 * 1024).fill(0x62);
var errorTriggered = false;
const srv = net.createServer( (conn) => {
// console.log('foo'); // Uncomment this line and the callback fires as expected.
conn.write(buf);
conn.on('error', () => { errorTriggered = true; }); // This callback isn't firing.
conn.on('close', () => { srv.unref(); });
}).listen(12346, () => {
const client = net.connect({ port: 12346 });
client.on('connect', () => { client.destroy(); });
});
process.on('exit', () => {
// Check that the callback fired.
assert(errorTriggered);
});
Tagging everyone that has been involved in previous issues where this has caused problems because they might have more insight to add here: @joaocgreis @bnoordhuis @mscdex @bengl
Ref: #4062