lua
lua
DIAdiscord.js - Imagine an app
Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
Ohhhh my god lol. Okay I'm gonna add that too
15 replies
DIAdiscord.js - Imagine an app
Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
YOU'RE RIGHT
15 replies
DIAdiscord.js - Imagine an app
Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
I FORGOT THE g
15 replies
DIAdiscord.js - Imagine an app
Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
I have rewritten the function as follows, just to be absolutely sure that this possible bug is gone:
function containsSupportedLink(message: Message): boolean {
const pattern = /https?:\/\/([\w.]+)((?:\/[^\s/#?]*)+)(\?[^\s#]*)?(#\S*)?/;
const content = String(message.content);

let i = 0;
let result: RegExpExecArray | null;

while ((result = pattern.exec(content)) != null) {
let [_, host, path, query, fragment] = result; host = host.toLowerCase();

if (host.endsWith('x.com') || host.endsWith('twitter.com')) {
if (/^\/\w+\/status\/\d+/i.test(path)) return true;
}

for (const domain of supportedMediaDomains) {
if (host.endsWith(domain) && hasSupportedExtension(path)) return true;
}

for (const domain of supportedDomains) {
if (host.endsWith(domain) && !/^\/*$/.test(path)) return true;
}

if (i++ > 1000) {
logger.warn('Exceeded link check limit?');
return false;
}
}

return false;
}
function containsSupportedLink(message: Message): boolean {
const pattern = /https?:\/\/([\w.]+)((?:\/[^\s/#?]*)+)(\?[^\s#]*)?(#\S*)?/;
const content = String(message.content);

let i = 0;
let result: RegExpExecArray | null;

while ((result = pattern.exec(content)) != null) {
let [_, host, path, query, fragment] = result; host = host.toLowerCase();

if (host.endsWith('x.com') || host.endsWith('twitter.com')) {
if (/^\/\w+\/status\/\d+/i.test(path)) return true;
}

for (const domain of supportedMediaDomains) {
if (host.endsWith(domain) && hasSupportedExtension(path)) return true;
}

for (const domain of supportedDomains) {
if (host.endsWith(domain) && !/^\/*$/.test(path)) return true;
}

if (i++ > 1000) {
logger.warn('Exceeded link check limit?');
return false;
}
}

return false;
}
15 replies
DIAdiscord.js - Imagine an app
Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
Apparently this was true at least in my testing, but checking on it in production it is seemingly getting stuck. I'm going to feel like such an idiot if this is the issue LOL.
15 replies
DIAdiscord.js - Imagine an app
Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
No description
15 replies
DIAdiscord.js - Imagine an app
Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
At least that's what I think! I am not /actively/ monitoring those two metrics.
15 replies
DIAdiscord.js - Imagine an app
Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
Additionally, it never actually gets stuck in a loop! Both CPU and memory usage stay way down, and the function in question is entirely synchronous (unless there's something evil going on).
15 replies
DIAdiscord.js - Imagine an app
Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
I know that it's not my issue, but thanks for bringing that up! @matt4499, I like the way you re-wrote the loop to make it more obvious and I'll copy that over into my codebase. That loop really just iterates over the results of the pattern regex and unless message.content changes, it will always terminate.
15 replies
DIAdiscord.js - Imagine an app
Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
The only thing I can think of next is to launch it in a debugger, learn a bunch about Discord.js's internals, and watch it and wait for it to lock up again.
15 replies
DIAdiscord.js - Imagine an app
Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
Another example:
2024-09-27T19:57:03.697239292Z [discord.js dbg] [WS => Shard 0] Heartbeat acknowledged, latency of 79ms.
2024-09-27T19:57:45.005351995Z [discord.js dbg] [WS => Shard 0] Heartbeat acknowledged, latency of 97ms.
(Docker sends SIGTERM)
(Docker sends SIGKILL 10s later)
(Process exits)
(Process created)
2024-09-27T20:00:12.187818342Z [mnsnd dbg] Starting up...
2024-09-27T20:00:12.245994300Z [discord.js dbg] Provided token: MTI1MzE1Mzc5MDE5MDY4MjEyMg.GekIOf.**************************************
2024-09-27T20:00:12.246347208Z [discord.js dbg] Preparing to connect to the gateway...
2024-09-27T19:57:03.697239292Z [discord.js dbg] [WS => Shard 0] Heartbeat acknowledged, latency of 79ms.
2024-09-27T19:57:45.005351995Z [discord.js dbg] [WS => Shard 0] Heartbeat acknowledged, latency of 97ms.
(Docker sends SIGTERM)
(Docker sends SIGKILL 10s later)
(Process exits)
(Process created)
2024-09-27T20:00:12.187818342Z [mnsnd dbg] Starting up...
2024-09-27T20:00:12.245994300Z [discord.js dbg] Provided token: MTI1MzE1Mzc5MDE5MDY4MjEyMg.GekIOf.**************************************
2024-09-27T20:00:12.246347208Z [discord.js dbg] Preparing to connect to the gateway...
15 replies