This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
net: unref() is not persistent #7077
Closed
Description
var net = require('net');
var server = net.createServer();
server.unref();
server.listen();
net.connect(server.address().port).unref();
It hangs because of the unref() that comes before listen() and the one after connect(). In that vein:
require('net').connect(42).unref();
It fails with ECONNREFUSED because the unref() is a no-op. The expected behavior for both scripts is that they simply quit. Affects v0.10 and master.
The documentation doesn't mention when it's okay to call unref(). For the sake of user friendliness, net.Socket and net.Server should remember the ref state and retroactively apply it when the handle is created. Probably applies to other handle types as well.