Skip to content

fix: prevent SSH timeout stacking in MirrorSQL#189

Open
jakebromberg wants to merge 3 commits intomainfrom
fix/36-ssh-timeout-stacking
Open

fix: prevent SSH timeout stacking in MirrorSQL#189
jakebromberg wants to merge 3 commits intomainfrom
fix/36-ssh-timeout-stacking

Conversation

@jakebromberg
Copy link
Member

@jakebromberg jakebromberg commented Feb 21, 2026

Summary

  • Each sshInstance() call in MirrorSQL created a new 5-minute setTimeout without clearing the previous one, causing dangling timeouts to stack on rapid repeated calls.
  • Stores the timeout handle as a static class property and calls clearTimeout on the existing handle before setting a new one.
  • Adds unit tests verifying only one timeout is active after multiple calls, and that superseded timeouts don't trigger premature disposal.

Test plan

  • New test: tests/unit/middleware/legacy/ssh-timeout.test.ts — confirms clearTimeout is called on prior handles and that only the latest timeout fires dispose().
  • Tests fail before fix, pass after fix.
  • Existing unit tests still pass (npm run test:unit).

Fixes #36

Made with Cursor

export class MirrorSQL {
private static _instance: MirrorSQL | null = null;
private static _ssh: NodeSSH | null = null;
private static _timeoutHandle: ReturnType<typeof setTimeout> | null = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file has been moved here and has similar changes: https://github.com/WXYC/Backend-Service/blob/main/shared/database/src/legacy/sql.mirror.ts

This PR should be converted to a cleanup to remove this file from living in the backend service.

Jake Bromberg and others added 3 commits March 9, 2026 23:01
Each sshInstance() call added a new 5-minute timeout without clearing
the previous one, stacking dangling timeouts on rapid repeated calls.

Co-authored-by: Cursor <cursoragent@cursor.com>
The MirrorSQL class moved from apps/backend/middleware/legacy/ to shared/database/src/legacy/. Updates the test import path and property names to match the current implementation.
@jakebromberg jakebromberg force-pushed the fix/36-ssh-timeout-stacking branch from f2de0f4 to b4ed7b2 Compare March 10, 2026 06:30
@jakebromberg jakebromberg requested a review from AyBruno March 10, 2026 06:45
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