fix: prevent thundering-herd of concurrent Syncthing REST API calls#15
Merged
Conversation
The background-thread refresh introduced in the previous commit had a new problem: _auto_refresh fires every 3s, but connected_devices() can take up to 30s (3 calls × 10s timeout). Without a guard, 10 overlapping refresh threads accumulate, each making 3 requests = 30 simultaneous requests to Syncthing's REST API, saturating it and making timeouts self-reinforcing. - Add _refreshing flag to _DevicesContent and IncomingWindow: a new fetch is skipped if one is already in flight; flag is cleared in _apply_refresh (or immediately if the window is gone). - Increase auto-refresh interval 3s → 10s in both windows to reduce steady-state API call rate. - Cache get_device_id() in SyncthingClient: the local device ID never changes, but was fetched on every connected_devices() call (every refresh cycle). - Make connected_devices() resilient: if get_connections() times out, return devices with unknown connection status instead of raising. - Downgrade PendingDeviceWatcher timeout logs from exception (full traceback) to warning: a ReadTimeout is routine when Syncthing is busy, not an unexpected crash. https://claude.ai/code/session_0128MyVVEu1Dt3jTeaZ1edyL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit was missed when the previous PRs (#12, #13) were merged.
What this fixes
The background-thread refresh introduced in #13 had a self-reinforcing timeout loop:
_auto_refreshfires every 3 secondsconnected_devices()can take up to 30 seconds (3 calls × 10s timeout each) when Syncthing is slowChanges
clipsync/ui.py_refreshingflag on_DevicesContentandIncomingWindow: skips a new fetch if one is already in flight; flag is cleared in_apply_refreshclipsync/syncthing.pyget_device_id()inSyncthingClient— the local device ID never changes, was being fetched on everyconnected_devices()callconnected_devices()catchesrequests.RequestExceptiononget_connections()and returns the device list with unknown connection status rather than failing entirelyclipsync/pairing.pyReadTimeoutlogs inPendingDeviceWatcherfrom full exception traceback → singleWARNINGlinehttps://claude.ai/code/session_0128MyVVEu1Dt3jTeaZ1edyL
Generated by Claude Code