chore: fix race in grid server (#9999)

This commit is contained in:
Andrey Lushnikov 2021-11-02 18:01:15 -07:00 committed by GitHub
parent 5abb5d74ea
commit 2e1dcaf2ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -101,7 +101,7 @@ class GridAgent extends EventEmitter {
private _ws: WebSocket | undefined;
readonly _workers = new Map<string, GridWorker>();
private _status: AgentStatus = 'none';
private _workersWaitingForAgentConnected: GridWorker[] = [];
private _workersWaitingForAgentConnected: Set<GridWorker> = new Set();
private _retireTimeout = 30000;
private _retireTimeoutId: NodeJS.Timeout | undefined;
private _log: debug.Debugger;
@ -135,7 +135,7 @@ class GridAgent extends EventEmitter {
this._log(`send worker id: ${worker.workerId}`);
ws.send(worker.workerId);
}
this._workersWaitingForAgentConnected = [];
this._workersWaitingForAgentConnected.clear();
}
canCreateWorker() {
@ -152,6 +152,7 @@ class GridAgent extends EventEmitter {
this._workers.set(worker.workerId, worker);
worker.on('close', () => {
this._workers.delete(worker.workerId);
this._workersWaitingForAgentConnected.delete(worker);
if (!this._workers.size) {
this.setStatus('retiring');
if (this._retireTimeoutId)
@ -164,7 +165,7 @@ class GridAgent extends EventEmitter {
this._log(`send worker id: ${worker.workerId}`);
this._ws.send(worker.workerId);
} else {
this._workersWaitingForAgentConnected.push(worker);
this._workersWaitingForAgentConnected.add(worker);
}
}