diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-12 21:53:57 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-12 21:53:57 +0200 |
commit | b0385e0fcbf6ac1cae46979cc495081319fd4dec (patch) | |
tree | c95199efa3ef5e76f39dc9bbf32f72f48642eb7c /gateway/src | |
parent | :zap: benchmark tests (diff) | |
download | server-b0385e0fcbf6ac1cae46979cc495081319fd4dec.tar.xz |
:zap: improve memory managment
Diffstat (limited to 'gateway/src')
-rw-r--r-- | gateway/src/events/Close.ts | 9 | ||||
-rw-r--r-- | gateway/src/util/Send.ts | 3 |
2 files changed, 9 insertions, 3 deletions
diff --git a/gateway/src/events/Close.ts b/gateway/src/events/Close.ts index 1299ad5c..5c1bd292 100644 --- a/gateway/src/events/Close.ts +++ b/gateway/src/events/Close.ts @@ -1,10 +1,13 @@ import { WebSocket } from "@fosscord/gateway"; -import { Message } from "./Message"; import { Session } from "@fosscord/util"; export async function Close(this: WebSocket, code: number, reason: string) { console.log("[WebSocket] closed", code, reason); if (this.session_id) await Session.delete({ session_id: this.session_id }); - // @ts-ignore - this.off("message", Message); + if (this.heartbeatTimeout) clearTimeout(this.heartbeatTimeout); + if (this.readyTimeout) clearTimeout(this.readyTimeout); + + this.deflate?.close(); + + this.removeAllListeners(); } diff --git a/gateway/src/util/Send.ts b/gateway/src/util/Send.ts index 4defa898..196d4205 100644 --- a/gateway/src/util/Send.ts +++ b/gateway/src/util/Send.ts @@ -18,6 +18,9 @@ export async function Send(socket: WebSocket, data: Payload) { } return new Promise((res, rej) => { + if (socket.readyState !== 1) { + return rej("socket not open"); + } socket.send(buffer, (err: any) => { if (err) return rej(err); return res(null); |