Skip to content

Force reconnect on suspend/resume during active sync session#19

Merged
guydols merged 1 commit into
mainfrom
dev
Jul 4, 2026
Merged

Force reconnect on suspend/resume during active sync session#19
guydols merged 1 commit into
mainfrom
dev

Conversation

@guydols

@guydols guydols commented Jul 4, 2026

Copy link
Copy Markdown
Owner

This pull request improves how the filesync client and GUI manager handle system suspend and resume events, ensuring that active connections are force-closed and sessions are promptly restarted after a resume. The main changes introduce a mechanism to track and close in-flight connections, and refactor the session loop to coordinate reconnects more reliably.

Connection management and forced disconnects:

  • Added an active_conn field to the Client struct, protected by a Mutex, to track the currently active connection. This allows shutdown() to force-close the connection even if the client is blocked in a session. [1] [2]
  • Introduced the ActiveConnGuard RAII struct to ensure active_conn is cleared when a session ends, preventing stale references.
  • Updated Client::shutdown() to force-close any active connection, unblocking any threads waiting on network I/O.
  • Modified Client::session() to check for shutdown before connecting and to set/clear the active_conn slot appropriately during the session lifecycle. [1] [2]

GUI session loop and suspend/resume handling:

  • Reworked the GUI session_loop to maintain an active_client reference, allowing the suspend-monitor thread to call shutdown() on the current client. Also introduced a resume_pending flag to coordinate immediate reconnects after resume. [1] [2] [3]
  • Added a dedicated suspend-monitor thread that listens for system resume events and triggers forced disconnects and immediate reconnects, ensuring the client does not wait out a stale backoff period after resume. [1] [2] [3]

These changes make the filesync client more robust in the face of system suspend/resume events, reducing downtime and improving user experience.

…sion

Previously the suspend/resume detector was only polled while paused or
during the fixed backoff wait between reconnect attempts, never while a
session was actively connected. Since the client sets no TCP keepalive,
a session that was live when the machine slept would resume holding a
dead socket with no way to detect it, so filesystem changes queued up
and silently failed to reach the server.

- Client now tracks its active Connection and shutdown() force-closes
  it, reusing the existing disconnect/reconnect error handling.
- gui::manager::session_loop spawns a dedicated suspend-monitor thread
  that runs for the life of the sync session and force-disconnects the
  active client (or skips the backoff wait) the moment a resume is
  detected, so reconnect + rescan happens the same way as at startup.
@guydols
guydols merged commit 3c49eb0 into main Jul 4, 2026
2 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.

1 participant