| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 09349a8 commit 20d3378
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -555,18 +555,18 @@ function workerInit() { | |||
| 555 | 555 | ||
| 556 | 556 | // obj is a net#Server or a dgram#Socket object. | |
| 557 | 557 | cluster._getServer = function(obj, options, cb) { | |
| 558 | - const key = [ options.address, | ||
| 559 | - options.port, | ||
| 560 | - options.addressType, | ||
| 561 | - options.fd ].join(':'); | ||
| 562 | - if (indexes[key] === undefined) | ||
| 563 | - indexes[key] = 0; | ||
| 558 | + const indexesKey = [ options.address, | ||
| 559 | + options.port, | ||
| 560 | + options.addressType, | ||
| 561 | + options.fd ].join(':'); | ||
| 562 | + if (indexes[indexesKey] === undefined) | ||
| 563 | + indexes[indexesKey] = 0; | ||
| 564 | 564 | else | |
| 565 | - indexes[key]++; | ||
| 565 | + indexes[indexesKey]++; | ||
| 566 | 566 | ||
| 567 | 567 | const message = util._extend({ | |
| 568 | 568 | act: 'queryServer', | |
| 569 | - index: indexes[key], | ||
| 569 | + index: indexes[indexesKey], | ||
| 570 | 570 | data: null | |
| 571 | 571 | }, options); | |
| 572 | 572 | ||
@@ -576,9 +576,9 @@ function workerInit() { | |||
| 576 | 576 | if (obj._setServerData) obj._setServerData(reply.data); | |
| 577 | 577 | ||
| 578 | 578 | if (handle) | |
| 579 | - shared(reply, handle, cb); // Shared listen socket. | ||
| 579 | + shared(reply, handle, indexesKey, cb); // Shared listen socket. | ||
| 580 | 580 | else | |
| 581 | - rr(reply, cb); // Round-robin. | ||
| 581 | + rr(reply, indexesKey, cb); // Round-robin. | ||
| 582 | 582 | }); | |
| 583 | 583 | obj.once('listening', function() { | |
| 584 | 584 | cluster.worker.state = 'listening'; | |
@@ -590,14 +590,15 @@ function workerInit() { | |||
| 590 | 590 | }; | |
| 591 | 591 | ||
| 592 | 592 | // Shared listen socket. | |
| 593 | - function shared(message, handle, cb) { | ||
| 593 | + function shared(message, handle, indexesKey, cb) { | ||
| 594 | 594 | var key = message.key; | |
| 595 | 595 | // Monkey-patch the close() method so we can keep track of when it's | |
| 596 | 596 | // closed. Avoids resource leaks when the handle is short-lived. | |
| 597 | 597 | var close = handle.close; | |
| 598 | 598 | handle.close = function() { | |
| 599 | 599 | send({ act: 'close', key: key }); | |
| 600 | 600 | delete handles[key]; | |
| 601 | + delete indexes[indexesKey]; | ||
| 601 | 602 | return close.apply(this, arguments); | |
| 602 | 603 | }; | |
| 603 | 604 | assert(handles[key] === undefined); | |
@@ -606,7 +607,7 @@ function workerInit() { | |||
| 606 | 607 | } | |
| 607 | 608 | ||
| 608 | 609 | // Round-robin. Master distributes handles across workers. | |
| 609 | - function rr(message, cb) { | ||
| 610 | + function rr(message, indexesKey, cb) { | ||
| 610 | 611 | if (message.errno) | |
| 611 | 612 | return cb(message.errno, null); | |
| 612 | 613 | ||
@@ -627,6 +628,7 @@ function workerInit() { | |||
| 627 | 628 | if (key === undefined) return; | |
| 628 | 629 | send({ act: 'close', key: key }); | |
| 629 | 630 | delete handles[key]; | |
| 631 | + delete indexes[indexesKey]; | ||
| 630 | 632 | key = undefined; | |
| 631 | 633 | } | |
| 632 | 634 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const cluster = require('cluster'); | ||
| 5 | + | ||
| 6 | + cluster.schedulingPolicy = cluster.SCHED_NONE; | ||
| 7 | + | ||
| 8 | + if (cluster.isMaster) { | ||
| 9 | + const worker1 = cluster.fork(); | ||
| 10 | + worker1.on('listening', common.mustCall(() => { | ||
| 11 | + const worker2 = cluster.fork(); | ||
| 12 | + worker2.on('exit', (code, signal) => { | ||
| 13 | + assert.strictEqual(code, 0, 'worker2 did not exit normally'); | ||
| 14 | + assert.strictEqual(signal, null, 'worker2 did not exit normally'); | ||
| 15 | + worker1.disconnect(); | ||
| 16 | + }); | ||
| 17 | + })); | ||
| 18 | + | ||
| 19 | + worker1.on('exit', common.mustCall((code, signal) => { | ||
| 20 | + assert.strictEqual(code, 0, 'worker1 did not exit normally'); | ||
| 21 | + assert.strictEqual(signal, null, 'worker1 did not exit normally'); | ||
| 22 | + })); | ||
| 23 | + } else { | ||
| 24 | + const net = require('net'); | ||
| 25 | + const server = net.createServer(); | ||
| 26 | + server.listen(common.PORT, common.mustCall(() => { | ||
| 27 | + if (cluster.worker.id === 2) { | ||
| 28 | + server.close(() => { | ||
| 29 | + server.listen(common.PORT, common.mustCall(() => { | ||
| 30 | + server.close(() => { | ||
| 31 | + process.disconnect(); | ||
| 32 | + }); | ||
| 33 | + })); | ||
| 34 | + }); | ||
| 35 | + } | ||
| 36 | + })); | ||
| 37 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const cluster = require('cluster'); | ||
| 5 | + | ||
| 6 | + cluster.schedulingPolicy = cluster.SCHED_RR; | ||
| 7 | + | ||
| 8 | + if (cluster.isMaster) { | ||
| 9 | + const worker1 = cluster.fork(); | ||
| 10 | + worker1.on('listening', common.mustCall(() => { | ||
| 11 | + const worker2 = cluster.fork(); | ||
| 12 | + worker2.on('exit', (code, signal) => { | ||
| 13 | + assert.strictEqual(code, 0, 'worker2 did not exit normally'); | ||
| 14 | + assert.strictEqual(signal, null, 'worker2 did not exit normally'); | ||
| 15 | + worker1.disconnect(); | ||
| 16 | + }); | ||
| 17 | + })); | ||
| 18 | + | ||
| 19 | + worker1.on('exit', common.mustCall((code, signal) => { | ||
| 20 | + assert.strictEqual(code, 0, 'worker1 did not exit normally'); | ||
| 21 | + assert.strictEqual(signal, null, 'worker1 did not exit normally'); | ||
| 22 | + })); | ||
| 23 | + } else { | ||
| 24 | + const net = require('net'); | ||
| 25 | + const server = net.createServer(); | ||
| 26 | + server.listen(common.PORT, common.mustCall(() => { | ||
| 27 | + if (cluster.worker.id === 2) { | ||
| 28 | + server.close(() => { | ||
| 29 | + server.listen(common.PORT, common.mustCall(() => { | ||
| 30 | + server.close(() => { | ||
| 31 | + process.disconnect(); | ||
| 32 | + }); | ||
| 33 | + })); | ||
| 34 | + }); | ||
| 35 | + } | ||
| 36 | + })); | ||
| 37 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments