From 7f41933763357119125b8ac388e957ad1c98a4ab Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 10 Oct 2021 11:02:25 +0200 Subject: :sparkles: changed and fixed compiler --- bundle/src/stats.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'bundle/src/stats.ts') diff --git a/bundle/src/stats.ts b/bundle/src/stats.ts index d5ceeff7..49705424 100644 --- a/bundle/src/stats.ts +++ b/bundle/src/stats.ts @@ -1,11 +1,19 @@ import os from "os"; import osu from "node-os-utils"; +import { red } from "nanocolors"; export function initStats() { console.log(`[Path] running in ${__dirname}`); console.log(`[CPU] ${osu.cpu.model()} Cores x${osu.cpu.count()}`); console.log(`[System] ${os.platform()} ${os.arch()}`); console.log(`[Process] running with pid: ${process.pid}`); + if (process.getuid() === 0) { + console.warn( + red( + `[Process] Warning fosscord is running as root, this highly discouraged and might expose your system vulnerable to attackers. Please run fosscord as a user without root privileges.` + ) + ); + } setInterval(async () => { const [cpuUsed, memory, network] = await Promise.all([ @@ -23,5 +31,5 @@ export function initStats() { process.memoryUsage().rss / 1024 / 1024 )}mb/${memory.totalMemMb.toFixed(0)}mb ${networkUsage}` ); - }, 1000 * 5); + }, 1000 * 10); } -- cgit 1.5.1 From f259a1fd3e4edc35f0f0694380f4e4b6fe237fba Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 10 Oct 2021 11:13:51 +0200 Subject: :bug: fix windows process.getuid --- bundle/src/stats.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bundle/src/stats.ts') diff --git a/bundle/src/stats.ts b/bundle/src/stats.ts index 49705424..18bb85ca 100644 --- a/bundle/src/stats.ts +++ b/bundle/src/stats.ts @@ -7,7 +7,7 @@ export function initStats() { console.log(`[CPU] ${osu.cpu.model()} Cores x${osu.cpu.count()}`); console.log(`[System] ${os.platform()} ${os.arch()}`); console.log(`[Process] running with pid: ${process.pid}`); - if (process.getuid() === 0) { + if (process.getuid && process.getuid() === 0) { console.warn( red( `[Process] Warning fosscord is running as root, this highly discouraged and might expose your system vulnerable to attackers. Please run fosscord as a user without root privileges.` -- cgit 1.5.1 From b0385e0fcbf6ac1cae46979cc495081319fd4dec Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Tue, 12 Oct 2021 21:53:57 +0200 Subject: :zap: improve memory managment --- bundle/src/stats.ts | 3 ++- gateway/src/events/Close.ts | 9 ++++++--- gateway/src/util/Send.ts | 3 +++ util/src/util/Event.ts | 2 ++ 4 files changed, 13 insertions(+), 4 deletions(-) (limited to 'bundle/src/stats.ts') diff --git a/bundle/src/stats.ts b/bundle/src/stats.ts index 18bb85ca..7928de89 100644 --- a/bundle/src/stats.ts +++ b/bundle/src/stats.ts @@ -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); } 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); diff --git a/util/src/util/Event.ts b/util/src/util/Event.ts index bf9547b1..8ed009d5 100644 --- a/util/src/util/Event.ts +++ b/util/src/util/Event.ts @@ -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; -- cgit 1.5.1