Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: no need for masterSocketServer to start for multiple times at sticky mode #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Master extends EventEmitter {
this.isProduction = isProduction(this.options);
this.agentWorkerIndex = 0;
this.closed = false;
this.masterSocketServerStarted = false;
this[REAL_PORT] = this.options.port;
this[PROTOCOL] = this.options.https ? 'https' : 'http';

Expand Down Expand Up @@ -273,8 +274,8 @@ class Master extends EventEmitter {
}
}
s = Number(s);
const pid = ws[s % workerNumbers];
return this.workerManager.getWorker(pid);
const workerId = ws[s % workerNumbers];
return this.workerManager.getWorker(workerId);
}

forkAgentWorker() {
Expand Down Expand Up @@ -503,9 +504,10 @@ class Master extends EventEmitter {
address.port = this.options.sticky ? this[REAL_PORT] : address.port;
this[APP_ADDRESS] = getAddress(address);

if (this.options.sticky) {
if (this.options.sticky && !this.masterSocketServerStarted) {
this.startMasterSocketServer(err => {
if (err) return this.ready(err);
this.masterSocketServerStarted = true;
this.ready(true);
});
} else {
Expand Down