mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 08:03:30 +01:00
fix(websocketshard): backport zombie connection fix (#9003)
This commit is contained in:
@@ -578,14 +578,10 @@ class WebSocketShard extends EventEmitter {
|
|||||||
}
|
}
|
||||||
this.wsCloseTimeout = setTimeout(() => {
|
this.wsCloseTimeout = setTimeout(() => {
|
||||||
this.setWsCloseTimeout(-1);
|
this.setWsCloseTimeout(-1);
|
||||||
this.debug(`[WebSocket] Close Emitted: ${this.closeEmitted}`);
|
|
||||||
// Check if close event was emitted.
|
// Check if close event was emitted.
|
||||||
if (this.closeEmitted) {
|
if (this.closeEmitted) {
|
||||||
this.debug(
|
this.debug(`[WebSocket] close was already emitted, assuming the connection was closed properly.`);
|
||||||
`[WebSocket] was closed. | WS State: ${
|
|
||||||
CONNECTION_STATE[this.connection?.readyState ?? WebSocket.CLOSED]
|
|
||||||
} | Close Emitted: ${this.closeEmitted}`,
|
|
||||||
);
|
|
||||||
// Setting the variable false to check for zombie connections.
|
// Setting the variable false to check for zombie connections.
|
||||||
this.closeEmitted = false;
|
this.closeEmitted = false;
|
||||||
return;
|
return;
|
||||||
@@ -593,13 +589,17 @@ class WebSocketShard extends EventEmitter {
|
|||||||
|
|
||||||
this.debug(
|
this.debug(
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
`[WebSocket] did not close properly, assuming a zombie connection.\nEmitting close and reconnecting again.`,
|
`[WebSocket] Close Emitted: ${this.closeEmitted} | did not close properly, assuming a zombie connection.\nEmitting close and reconnecting again.`,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.emitClose();
|
if (this.connection) this._cleanupConnection();
|
||||||
// Setting the variable false to check for zombie connections.
|
|
||||||
this.closeEmitted = false;
|
this.emitClose({
|
||||||
}, time).unref();
|
code: 4009,
|
||||||
|
reason: 'Session time out.',
|
||||||
|
wasClean: false,
|
||||||
|
});
|
||||||
|
}, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -824,14 +824,11 @@ class WebSocketShard extends EventEmitter {
|
|||||||
this._emitDestroyed();
|
this._emitDestroyed();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.connection?.readyState === WebSocket.CLOSING || this.connection?.readyState === WebSocket.CLOSED) {
|
this.debug(
|
||||||
this.closeEmitted = false;
|
`[WebSocket] Adding a WebSocket close timeout to ensure a correct WS reconnect.
|
||||||
this.debug(
|
|
||||||
`[WebSocket] Adding a WebSocket close timeout to ensure a correct WS reconnect.
|
|
||||||
Timeout: ${this.manager.client.options.closeTimeout}ms`,
|
Timeout: ${this.manager.client.options.closeTimeout}ms`,
|
||||||
);
|
);
|
||||||
this.setWsCloseTimeout(this.manager.client.options.closeTimeout);
|
this.setWsCloseTimeout(this.manager.client.options.closeTimeout);
|
||||||
}
|
|
||||||
|
|
||||||
// Step 2: Null the connection object
|
// Step 2: Null the connection object
|
||||||
this.connection = null;
|
this.connection = null;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ process.send(123);
|
|||||||
|
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
console.log('Ready', client.options.shards);
|
console.log('Ready', client.options.shards);
|
||||||
if (client.options.shards === 0) {
|
if (client.options.shards[0] === 0) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log('kek dying');
|
console.log('kek dying');
|
||||||
client.destroy();
|
client.destroy();
|
||||||
|
|||||||
Reference in New Issue
Block a user