Skip to content

fix: connection resilience, sync-on-save — fixes #287, #299, #309, #323#374

Open
iamhyc wants to merge 2 commits into
masterfrom
connection-enhance
Open

fix: connection resilience, sync-on-save — fixes #287, #299, #309, #323#374
iamhyc wants to merge 2 commits into
masterfrom
connection-enhance

Conversation

@iamhyc
Copy link
Copy Markdown
Member

@iamhyc iamhyc commented May 8, 2026

Summary

Two fixes on the connection-enhance branch that address four long-standing issues with connection stability and local-replica sync behavior.


Commit 1: Connection resilience (3610590)

Fixes: #309, #287

Root cause: socket.io init() created new TCP connections without properly disconnecting old ones, leaving orphaned connections. When the server sent late data on abandoned connections, the OS TCP stack responded with RST, which could cause the server to drop all connections from this client. After sleep/lock, connections were silently broken while the UI showed "connected."

Changes:

Area Change
src/api/base.ts Enable socket.io auto-reconnect (1s–16s backoff, 10 attempts); HTTP retry for transient errors (5xx, ECONNRESET, ETIMEDOUT)
src/api/socketio.ts Properly disconnect() old socket (FIN not RST); fix EventBus listener leak; v2→v1 fallback
src/core/remoteFileSystemProvider.ts Exponential backoff (3→5 retries); 2s disconnect debounce; progress notification during reconnect; "Retry" button
src/collaboration/clientManager.ts 15s grace period before clearing collaborators; "Reconnecting..." indicator instead of immediate "Not connected"

Commit 2: Sync on explicit save (f2e3f63)

Fixes: #323, #299

Root cause: The local file system watcher (localWatcher.onDidChange) fired for all file modifications — including git operations (checkout, revert, discard) and LaTeX compilation outputs. This pushed unintended changes to Overleaf, causing data loss (#323) and zeroed-out PDFs (#299).

Change: Replaced localWatcher.onDidChange with vscode.workspace.onDidSaveTextDocument. Now only explicit user saves in the editor trigger a push to Overleaf. File creation/deletion watchers and pull-direction (Overleaf→local) sync are unchanged.

Before After
Any file system write → push to Overleaf Only editor save → push to Overleaf
Git checkout, compilation outputs → push (bug) Git checkout, compilation outputs → no push
Extension's own pull-writes → echo loop (mitigated by hash cache) Extension's own pull-writes → no echo at all

Issues Closed

GitHub Copilot added 2 commits May 8, 2026 21:25
…onnection lost (fixes #309)

Root cause: socket.io init() created new TCP connections without
disconnecting old ones, causing orphaned connections. The OS TCP stack
responded with RST when the server sent late/out-of-order data on
abandoned connections, which could cause the server to drop ALL
connections from this client.

Changes by file:

- src/api/base.ts:
  - Enable socket.io auto-reconnect (reconnect: true, delay 1s-16s, 10
    attempts) instead of manual socket recreation on every transient
    hiccup
  - Add HTTP request retry (up to 2x) for transient errors (5xx,
    ECONNRESET, ETIMEDOUT, ECONNREFUSED, ENOTFOUND)

- src/api/socketio.ts:
  - Properly disconnect old socket (removeAllListeners + disconnect)
    before creating new one to send FIN instead of RST
  - Disable auto-reconnect on connectionRejected to prevent futile
    reconnect->reject->reconnect loops
  - Fix EventBus listener leak (MaxListenersExceededWarning) by
    tracking Disposables and cleaning up before reinit
  - Add v2->v1 fallback when both schemes rejected
  - Replace unsafe throw with console.error on socket error events
  - Track _socketInitScheme; expose needsReinit getter

- src/core/remoteFileSystemProvider.ts:
  - Exponential backoff: 3->5 retries, 0s->1s/2s/4s/8s/16s delays
  - Only recreate socket on scheme change (needsReinit), not on every
    retry; let socket.io auto-reconnect handle transient disconnects
  - 2s disconnect debounce to ignore rapid connect/disconnect cycles
  - 1s delay before initiating reconnection after disconnect
  - Show 'Reconnecting to {server}...' progress notification during
    retries instead of silent failures
  - Add 'Retry' button alongside 'Reload' in error dialog
  - Reset retry state on connectionAccepted

- src/collaboration/clientManager.ts:
  - 15s grace period before clearing collaborator decorations on
    disconnect; show 'Reconnecting...' spin indicator instead
  - Only show red 'Not connected' after grace period expires

- l10n/bundle.l10n.json:
  - Add localization strings: Retry, Reconnecting..., Reconnecting to
    {serverName}..., Connection interrupted...
@iamhyc iamhyc requested a review from QianrenLi May 8, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant