| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f2f7d7b commit ce3a22a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,6 +111,10 @@ cluster._getServer = function(obj, options, cb) { | |||
| 111 | 111 | }); | |
| 112 | 112 | ||
| 113 | 113 | obj.once('listening', () => { | |
| 114 | + // short-lived sockets might have been closed | ||
| 115 | + if (!indexes.has(indexesKey)) { | ||
| 116 | + return; | ||
| 117 | + } | ||
| 114 | 118 | cluster.worker.state = 'listening'; | |
| 115 | 119 | const address = obj.address(); | |
| 116 | 120 | message.act = 'listening'; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + // Ensure that closing dgram sockets in 'listening' callbacks of cluster workers | ||
| 3 | + // won't throw errors. | ||
| 4 | + | ||
| 5 | + const common = require('../common'); | ||
| 6 | + const dgram = require('dgram'); | ||
| 7 | + const cluster = require('cluster'); | ||
| 8 | + if (common.isWindows) | ||
| 9 | + common.skip('dgram clustering is currently not supported on windows.'); | ||
| 10 | + | ||
| 11 | + if (cluster.isPrimary) { | ||
| 12 | + for (let i = 0; i < 3; i += 1) { | ||
| 13 | + cluster.fork(); | ||
| 14 | + } | ||
| 15 | + } else { | ||
| 16 | + const socket = dgram.createSocket('udp4'); | ||
| 17 | + | ||
| 18 | + socket.on('error', common.mustNotCall()); | ||
| 19 | + | ||
| 20 | + socket.on('listening', common.mustCall(() => { | ||
| 21 | + socket.close(); | ||
| 22 | + })); | ||
| 23 | + | ||
| 24 | + socket.on('close', common.mustCall(() => { | ||
| 25 | + cluster.worker.disconnect(); | ||
| 26 | + })); | ||
| 27 | + | ||
| 28 | + socket.bind(0); | ||
| 29 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments