Skip to content

fix: back off when a reconnect attempt fails before connecting - #89

Merged
LukeGus merged 2 commits into
Termix-SSH:dev-1.4.1from
Li-Lee:fix/reconnect-backoff-after-failed-attempt
Nov 16, 2026
Merged

LukeGus merged 2 commits into
Termix-SSH:dev-1.4.1from
Li-Lee:fix/reconnect-backoff-after-failed-attempt

Conversation

@Li-Lee

@Li-Lee Li-Lee commented Nov 16, 2026

Copy link
Copy Markdown

Problem

Right after the computer wakes, a terminal tab whose connection dropped fills its connection log with "Connection closed unexpectedly. This may be due to a reverse proxy or SSL configuration issue. Please check server logs." In one tab I counted 134 of them within about a second, until the network was back. The proxy and SSL hint is misleading here: the attempts never left the computer.

Cause

On an abnormal close (1006) the close listener reconnects with backoff only when wasConnectedRef is set. connectToHost resets that flag, so a reconnect attempt that fails before connecting (the network is not back yet after the wake) takes the other branch, which is meant for a first connection that fails. That branch shows the error and sets isConnecting to false, but leaves shouldNotReconnectRef alone. The effect that connects a visible tab that is neither connected nor connecting then calls connectToHost again after two animation frames. That attempt fails at once again, and so on for as long as the network is down. Each pass adds the warning, and since isReconnectingRef is false on that path, connectToHost also resets reconnectAttempts, so the attempt limit never applies.

A tab's first connection that fails loops the same way while the server cannot be reached.

Fix

  • A failed attempt during a reconnect (reconnectAttempts > 0) goes on with attemptReconnection: the usual 2/4/8 second waits, and the Disconnected screen after the last attempt.
  • A tab's first connection that fails stops at the error with shouldNotReconnectRef, as a rejected connection (1000/1005) and an expired login (1008) already do, so the effect does not retry it on the next frame. The error screen offers Reconnect.

Frontend only, one branch in the close listener. CHANGELOG entry under 1.4.1.

Testing

  • New abnormal-close-backoff.test.ts runs the 1006 branch and the auto-connect effect from the source, as auto-reconnect.test.ts does. A failed reconnect attempt keeps backing off; a failed first connection stops and the effect does not call connectToHost again. Both of those cases fail without the change.
  • Full suite 717/717, typecheck, and Prettier pass.
  • Ran the same change as a patch on SSH Terminal 1.3.0 in the macOS desktop app: after a sleep and wake the connection log showed one warning instead of the flood, and the tab reconnected.

🤖 Generated with Claude Code

An abnormal close (1006) only reconnected with backoff when
wasConnectedRef was set. connectToHost resets that flag, so when a
reconnect attempt itself failed before connecting (the network still
down right after the computer wakes), the close took the "first
connection failed" branch: it showed the error and set isConnecting to
false. The effect that connects a visible tab then called connectToHost
again on the next frame, which failed at once again, many times a
second until the network came back, each time adding "Connection closed
unexpectedly" to the connection log.

A failed attempt during a reconnect (reconnectAttempts > 0) now goes on
with attemptReconnection's backoff. A tab's first connection that fails
stops at the error like a rejected connection or an expired login does,
so the effect does not retry it on the next frame; the error screen
offers Reconnect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@termix-triage-bot

termix-triage-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

AI review | Looks safe to merge

The PR fixes a frontend logic bug where a terminal tab floods the connection log with warnings when a reconnect attempt fails before establishing a connection. The change adjusts the reconnect condition and sets a flag to stop immediate retries, accompanied by a targeted test and a compliant CHANGELOG entry. No security or stability risks found.

Reviewed 9e3f5bb. AI can be wrong, a maintainer still decides. Comment /termix review to run it again.

LukeGus
LukeGus previously approved these changes Nov 16, 2026

@LukeGus LukeGus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@LukeGus LukeGus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@LukeGus
LukeGus merged commit b4670ff into Termix-SSH:dev-1.4.1 Nov 16, 2026
4 checks passed
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