Skip to content

GeoLocation and IPFilter background refresh flags can race and remain stuck

Summary

GeoLocation and IPFilter background refresh start their worker threads before marking refresh as queued. A fast worker failure or completion can post back to the UI and clear the flag before the starter sets it, leaving refresh stuck as in progress.

This blocks Beta 0.7.3 because automatic protection and geolocation refresh should not silently wedge after a fast failure or shutdown edge case.

Evidence

GeoLocation:

  • srchybrid/GeoLocation.cpp:763 starts the background thread.
  • srchybrid/GeoLocation.cpp:772 sets m_bBackgroundRefreshQueued = true.
  • srchybrid/GeoLocation.cpp:1019 posts completion.
  • srchybrid/GeoLocation.cpp:780 clears the flag.

IPFilter:

  • srchybrid/IPFilterUpdater.cpp:367 starts the background thread.
  • srchybrid/IPFilterUpdater.cpp:375 sets m_bBackgroundRefreshQueued = true.
  • srchybrid/IPFilterUpdater.cpp:421 posts completion.
  • srchybrid/IPFilterUpdater.cpp:382 clears the flag.

Execution Plan

  1. Revalidate the refresh state machines for manual, automatic, failed, and shutdown paths.
  2. Set the queued/running flag before the worker can post completion, or add an operation token that lets stale completions be ignored safely.
  3. Make thread launch failure restore idle state and clean temporary files.
  4. Make failed completion posts during shutdown terminal and non-wedging.
  5. Apply the same pattern to both GeoLocation and IPFilter updater.
  6. Add tests/seams for immediate worker failure and completion-before-return.

Acceptance Criteria

  • Immediate worker completion cannot leave refresh permanently queued.
  • Manual retry after a failed refresh is possible.
  • Automatic refresh does not start overlapping workers.
  • Temporary files are cleaned on launch failure and worker failure.

Validation

  • 2026-05-08: Done in app commit e5c8f81.
  • python -m emule_workspace validate --workspace-root .
  • python -m emule_workspace build app --workspace-root . --config Release --platform x64 --variant main
  • Code validation: GeoLocation and IPFilter updater workers are created suspended, the queued flag is set before the worker can run, temporary files are cleaned and the flag is cleared on launch failure, and the worker context is released before ResumeThread().