mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Fix connection shutdown logic
Fix the WebSocket link not being properly teared down on the master side causing the handshake to deadlock when the slave tried to connect again.
This commit is contained in:
1 parent
d4e072f376
commit
4c26fcee3a
3 files changed
+30
-22
No files matched your search
+13
-7
@@ -90,14 +90,24 @@ class WebSocketBaseConnector extends events.EventEmitter {
|
||||
* @returns the sequence number of the message sent
|
||||
*/
|
||||
send(type, data) {
|
||||
this._check(["handshake", "connected"]);
|
||||
this._check(["handshake", "connected", "closing"]);
|
||||
let message = { seq: this._seq, type, data };
|
||||
this._sendBuffer.push(message);
|
||||
if (this._state === "connected") {
|
||||
if (["connected", "closing"].includes(this._state)) {
|
||||
this._socket.send(JSON.stringify(message));
|
||||
}
|
||||
return this._seq++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set connection state to closing
|
||||
*
|
||||
* Signal the connection is about tho close and that once the close
|
||||
* frame is received it should be considered finished.
|
||||
*/
|
||||
setClosing() {
|
||||
this._state = "closing";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,12 +166,8 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
|
||||
}
|
||||
|
||||
this.stopHeartbeat();
|
||||
|
||||
if (["handshake", "connected"].includes(this._state)) {
|
||||
this._socket.close(code, reason);
|
||||
}
|
||||
|
||||
this._state = "closing";
|
||||
this._socket.close(code, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -224,6 +224,7 @@ class Link {
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
this.connector.setClosing();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user