mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 23:14:53 +09:00
Fix unhandled rejection on disconnect (#582)
If a link is closed while the prepareDisconnect action is in progress the link will still try to signal the disconnect ready over the socket when the prepareDisconnect action completes, which throws due to the socket no longer being present. This error is not caught due to the catch happening before the finally on the promise and triggers an unhandled rejection. Fix by rearranging the finally to come before the catch on the promise so that errors are always handled, and checking that the link still has a session before attempting to send the disconnect ready signal.
This commit is contained in:
1 parent
520007c8d1
commit
48c31b4825
3 files changed
+10
-9
No files matched your search
@@ -5,6 +5,7 @@
|
||||
## Changes
|
||||
|
||||
- Fixed an unhandled error in Subspace Storage crashing the host.
|
||||
- Fixed an unhandled rejection in disconnect logic crashing the host.
|
||||
|
||||
|
||||
## Version 2.0.0-alpha.16
|
||||
|
||||
@@ -126,16 +126,15 @@ export class Link {
|
||||
});
|
||||
|
||||
connector.on("disconnectPrepare", () => {
|
||||
this.prepareDisconnect().catch(
|
||||
err => {
|
||||
logger.error(`Unexpected error preparing disconnect:\n${err.stack}`);
|
||||
this.prepareDisconnect().finally(() => {
|
||||
// Only WebSocket connectors issue disconnection events.
|
||||
const webSocketConnector = this.connector as WebSocketBaseConnector;
|
||||
if (webSocketConnector.hasSession) {
|
||||
webSocketConnector.sendDisconnectReady();
|
||||
}
|
||||
).finally(
|
||||
() => {
|
||||
// Only WebSocket connectors issue disconnection events.
|
||||
(this.connector as WebSocketBaseConnector).sendDisconnectReady();
|
||||
},
|
||||
);
|
||||
}).catch(err => {
|
||||
logger.error(`Unexpected error preparing disconnect:\n${err.stack}`);
|
||||
});
|
||||
});
|
||||
|
||||
connector.on("invalidate", () => {
|
||||
|
||||
@@ -73,6 +73,7 @@ class MockConnector extends lib.BaseConnector {
|
||||
super(src, dst);
|
||||
|
||||
this.connected = true;
|
||||
this.hasSession = true;
|
||||
this.sentMessages = [];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user