Clean up probe connection in case of EADDRINUSE for Unix socket listeners

This commit is contained in:
Tony Garnock-Jones 2018-12-12 17:12:15 +00:00
parent 4fb9a066b9
commit b85e8ee61f
1 changed files with 6 additions and 2 deletions

View File

@ -56,7 +56,11 @@ spawn named 'NetDriver' {
} else {
retried = true;
const probe = new net.Socket();
function destroyProbe() {
try { probe.destroy() } catch (e) { console.error(e); }
}
probe.on('error', Dataspace.wrapExternal((e) => {
destroyProbe();
if (e.code === 'ECONNREFUSED') {
fs.unlinkSync(path);
server.listen(path);
@ -66,8 +70,8 @@ spawn named 'NetDriver' {
throw err;
}
}));
probe.connect(path, Dataspace.wrapExternal((sock) => {
try { sock.destroy() } catch (e) { console.error(e); }
probe.connect(path, Dataspace.wrapExternal(() => {
destroyProbe();
throw err;
}));
}