| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1970,7 +1970,11 @@ function listenInCluster(server, address, port, addressType, | |||
| 1970 | 1970 | const ex = new ExceptionWithHostPort(err, 'bind', address, port); | |
| 1971 | 1971 | return server.emit('error', ex); | |
| 1972 | 1972 | } | |
| 1973 | - | ||
| 1973 | + // If there was a handle, just close it to avoid fd leak | ||
| 1974 | + // but it doesn't look like that's going to happen right now | ||
| 1975 | + if (server._handle) { | ||
| 1976 | + server._handle.close(); | ||
| 1977 | + } | ||
| 1974 | 1978 | // Reuse primary's server handle | |
| 1975 | 1979 | server._handle = handle; | |
| 1976 | 1980 | // _listen2 sets up the listened handle, it is still named like this | |
@@ -1999,6 +2003,8 @@ Server.prototype.listen = function(...args) { | |||
| 1999 | 2003 | ||
| 2000 | 2004 | options = options._handle || options.handle || options; | |
| 2001 | 2005 | const flags = getFlags(options.ipv6Only); | |
| 2006 | + // Refresh the id to make the previous call invalid | ||
| 2007 | + this._listeningId++; | ||
| 2002 | 2008 | // (handle[, backlog][, cb]) where handle is an object with a handle | |
| 2003 | 2009 | if (options instanceof TCP) { | |
| 2004 | 2010 | this._handle = options; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,38 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const net = require('net'); | ||
| 4 | + const cluster = require('cluster'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + if (cluster.isPrimary) { | ||
| 8 | + const worker = cluster.fork(); | ||
| 9 | + worker.on('exit', common.mustCall((code) => { | ||
| 10 | + assert.ok(code === 0); | ||
| 11 | + })); | ||
| 12 | + } else { | ||
| 13 | + const server = net.createServer(); | ||
| 14 | + server.listen(); | ||
| 15 | + try { | ||
| 16 | + // Currently, we can call `listen` twice in cluster worker, | ||
| 17 | + // if we can not call `listen` twice in the futrue, | ||
| 18 | + // just skip this test. | ||
| 19 | + server.listen(); | ||
| 20 | + } catch (e) { | ||
| 21 | + console.error(e); | ||
| 22 | + process.exit(0); | ||
| 23 | + } | ||
| 24 | + let i = 0; | ||
| 25 | + process.on('internalMessage', (msg) => { | ||
| 26 | + if (msg.cmd === 'NODE_CLUSTER') { | ||
| 27 | + if (++i === 2) { | ||
| 28 | + setImmediate(() => { | ||
| 29 | + server.close(() => { | ||
| 30 | + process.disconnect(); | ||
| 31 | + }); | ||
| 32 | + }); | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + }); | ||
| 36 | + // Must only call once | ||
| 37 | + server.on('listening', common.mustCall()); | ||
| 38 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments