Reset _chorusHubClient in RecheckNetworkStatus to allow re-discovery#381
Reset _chorusHubClient in RecheckNetworkStatus to allow re-discovery#381imnasnainaec wants to merge 4 commits into
Conversation
…vered Without the reset, the guard in CheckNetworkStatusAndUpdateUI short-circuited on the stale client and never re-ran server discovery, so a different ChorusHub server on the network was not found until the application restarted. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…click Nulling _chorusHubClient but leaving _chorusHubServerInfo stale is inconsistent when the intent is full re-discovery. Reset both in RecheckNetworkStatus. The reset creates a race window (up to 2s until the next timer tick starts the worker) where the button is still enabled but both fields are null. Guard the button click handler so a click during that window is a no-op rather than a NullReferenceException. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Nulling _chorusHubServerInfo on the UI thread while the worker thread reads it unsynchronized in CheckNetworkStatusAndUpdateUI would cause a NullReferenceException with no catch to recover. Nulling _chorusHubClient alone is sufficient: the worker's existing guard re-runs FindServerInformation and reassigns both fields before creating a new client. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This is incorrect; the AI tool didn't dig deep enough. Setting I'm also a little suspicious of the suggested fix in the first place. Surely the intended behavior of RecheckNetworkStatus is to check if the existing server is still connected, and only look for a new one if the first server has gone away? I don't think clearing the existing This feels like an AI hallucination to me, solving a problem that doesn't actually exist (and solving it wrong, as well). Is there any indication that this is an actual problem? Or is this a case of an AI tool finding hypothetical problems that don't actually happen? |
|
You're right — thanks for digging in. The null guard in the click handler only existed to patch the race the nulling introduced, so it goes too. Closing this PR; I'll note the rescoping in #374 and close that as well. (Response by Claude Fable 5.) |
`RecheckNetworkStatus()` in `SyncStartControl` creates a new worker thread but never clears `_chorusHubClient`. The worker method's guard skips server discovery when the field is non-null, so after the first check the stale client is reused permanently. If the ChorusHub server changes, the new server is never found until the application restarts.
Add `_chorusHubClient = null;` in `RecheckNetworkStatus()` before setting up the new worker. Nulling `_chorusHubClient` alone is sufficient to force re-discovery: the worker's existing `if (_chorusHubClient == null)` guard already calls `FindServerInformation()` and reassigns both `_chorusHubServerInfo` and `_chorusHubClient`.
Also add a null guard in `_useLocalNetworkButton_Click` for `_chorusHubClient` and `_chorusHubServerInfo`. Both run on the UI thread so there is no TOCTOU issue, but there is a ~2s race window between the null assignment and the next timer tick starting the new worker, during which the button remains enabled. The guard is a silent defensive return for that edge case.
Fixes #374
Devin review: https://app.devin.ai/review/sillsdev/chorus/pull/381
This change is