Skip to content

Conversation

@zhiyan114
Copy link
Owner

Make resources less dependent on CoreClient..


// Shared Services
const svcClient = new ServiceClient();
svcClient.start();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: svcClient.start() is an async method but is not awaited. Dependent clients are initialized immediately after and may try to access services like Prisma before they are ready, causing a crash.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The ServiceClient.start() method, which is an async function responsible for initializing connections to Prisma and Redis, is called without being awaited. Immediately following this, other clients like DiscordClient are initialized and started. These dependent clients, such as DiscordCommandHandler, then attempt to access database resources via service.prisma before the connection is guaranteed to be established. This race condition will cause runtime errors and application crashes during startup if the service initialization is slower than the execution of dependent code.

💡 Suggested Fix

Ensure service initialization completes before dependent clients are started by changing the call on line 19 of src/index.ts to await svcClient.start();.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/index.ts#L19

Potential issue: The `ServiceClient.start()` method, which is an `async` function
responsible for initializing connections to Prisma and Redis, is called without being
awaited. Immediately following this, other clients like `DiscordClient` are initialized
and started. These dependent clients, such as `DiscordCommandHandler`, then attempt to
access database resources via `service.prisma` before the connection is guaranteed to be
established. This race condition will cause runtime errors and application crashes
during startup if the service initialization is slower than the execution of dependent
code.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 8145649

Comment on lines +54 to +55
await TwitchCli.dispose();
await TwitchCli.dispose();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The shutdown handler does not call svcClient.dispose(), causing resource leaks from the web server, Prisma, and Redis. It also contains a duplicate call to TwitchCli.dispose().
Severity: HIGH | Confidence: High

🔍 Detailed Analysis

The application's shutdown handler fails to call svcClient.dispose(), which is responsible for closing the Express web server, disconnecting the Prisma client, and quitting the Redis connection. This omission leads to resource leaks, as these critical resources are not properly cleaned up when the application terminates. Additionally, the handler incorrectly calls TwitchCli.dispose() twice while omitting a call to YoutubeCli.dispose().

💡 Suggested Fix

In the shutdown handler within src/index.ts, add a call to await svcClient.dispose() to ensure proper resource cleanup. Also, remove the duplicate call to await TwitchCli.dispose().

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/index.ts#L54-L55

Potential issue: The application's shutdown handler fails to call `svcClient.dispose()`,
which is responsible for closing the Express web server, disconnecting the Prisma
client, and quitting the Redis connection. This omission leads to resource leaks, as
these critical resources are not properly cleaned up when the application terminates.
Additionally, the handler incorrectly calls `TwitchCli.dispose()` twice while omitting a
call to `YoutubeCli.dispose()`.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 8145649

@zhiyan114 zhiyan114 merged commit 146a6eb into master Jan 5, 2026
3 of 4 checks passed
@zhiyan114 zhiyan114 deleted the dev branch January 5, 2026 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants