Skip to content

Comments

Fix connection resets and heartbeat errors#157

Open
benrobson wants to merge 1 commit intostagingfrom
fix/connection-reset-heartbeat-errors-17554862004116618049
Open

Fix connection resets and heartbeat errors#157
benrobson wants to merge 1 commit intostagingfrom
fix/connection-reset-heartbeat-errors-17554862004116618049

Conversation

@benrobson
Copy link
Member

The application was suffering from instability manifested as read ECONNRESET errors and Discord heartbeat failures. Investigation revealed that the API routes (which the website calls recursively via fetch) were using a buggy callback pattern that often led to multiple response attempts or hanging requests, overwhelming the server and the MySQL connection pool.

This PR fixes these issues by:

  • Adding explicit error listeners to the MySQL connection pool and Discord client to prevent unhandled socket errors from destabilizing the process.
  • Refactoring the API layer to use modern async/await patterns, ensuring that each request receives exactly one response and that database operations are correctly awaited.
  • Cleaning up messy duplicate imports in app.js that could cause multiple module initializations.
  • Enhancing security by moving away from string interpolation in SQL queries where possible.

PR created automatically by Jules for task 17554862004116618049 started by @benrobson

… connections and refactoring API routes

This commit addresses the reported `read ECONNRESET` and heartbeat errors by:
1. Adding pool-level error handling to the MySQL database controller.
2. Adding error and shardError listeners to the Discord client.
3. Refactoring all major API routes to use async/await with Promises for database queries, ensuring proper response flow control and preventing 'Reply already sent' errors.
4. Cleaning up redundant imports in app.js.
5. Updating common API helpers to return status and be used more robustly in routes.
6. Using parameterized SQL queries in several locations to improve security.

Co-authored-by: benrobson <15405528+benrobson@users.noreply.github.com>
@google-labs-jules
Copy link

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@benrobson benrobson requested a review from JaedanC as a code owner February 22, 2026 02:37
@coderabbitai
Copy link

coderabbitai bot commented Feb 22, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/connection-reset-heartbeat-errors-17554862004116618049

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant