mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 05:02:37 +01:00
⚡ improve memory managment
This commit is contained in:
parent
7b28973fe5
commit
f2e8e2e031
@ -31,5 +31,6 @@ export function initStats() {
|
||||
process.memoryUsage().rss / 1024 / 1024
|
||||
)}mb/${memory.totalMemMb.toFixed(0)}mb ${networkUsage}`
|
||||
);
|
||||
}, 1000 * 10);
|
||||
// TODO: node-os-utils might have a memory leak, more investigation needed
|
||||
}, 1000 * 60 * 5);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -46,7 +46,9 @@ export async function listenEvent(event: string, callback: (event: EventOpts) =>
|
||||
} else {
|
||||
const cancel = () => {
|
||||
events.removeListener(event, callback);
|
||||
events.setMaxListeners(events.getMaxListeners() - 1);
|
||||
};
|
||||
events.setMaxListeners(events.getMaxListeners() + 1);
|
||||
events.addListener(event, (opts) => callback({ ...opts, cancel }));
|
||||
|
||||
return cancel;
|
||||
|
Loading…
Reference in New Issue
Block a user