Skip to content

fix(core-runtime): harden SingleInstanceManager for macOS#165

Open
kdroidFilter wants to merge 2 commits intomainfrom
fix/single-instance-macos
Open

fix(core-runtime): harden SingleInstanceManager for macOS#165
kdroidFilter wants to merge 2 commits intomainfrom
fix/single-instance-macos

Conversation

@kdroidFilter
Copy link
Copy Markdown
Owner

Summary

Fixes #161 — single instance mechanism broken on macOS since v1.6.0.

  • Retry on lock acquisition: tryLockWithRetry() retries 3× with 150ms delay, handling the race condition where a rapid relaunch overlaps with the previous process's shutdown hook
  • Fail-open on IOException: the IOException catch now returns true instead of false, preventing silent app termination when the lock mechanism encounters filesystem errors
  • Stale file cleanup: cleans orphan .restore_request files on primary startup and before re-creating them in sendRestoreRequest, avoiding FileAlreadyExistsException from crash leftovers

Test plan

  • Unit tests for tryLockWithRetry, stale file handling, configuration, lock semantics (10 tests)
  • Multi-process integration tests launching real JVM child processes (7 tests):
    • Single instance acquires lock and exits cleanly
    • Second instance is denied while first holds the lock
    • Relaunch succeeds after clean exit
    • Relaunch succeeds after kill -9 (stale lock file)
    • Rapid relaunch succeeds thanks to retry mechanism
    • Stale .restore_request file does not prevent launch
    • Primary receives restore request from secondary via WatchService
  • detekt passes with no violations

…nditions and stale files

Fixes #161 — single instance mechanism broken on macOS since v1.6.0.

- Add retry mechanism (3×150ms) on tryLock() to handle rapid relaunch
  race conditions where the previous shutdown hook hasn't released yet
- Change IOException catch from fail-closed (return false → app exits)
  to fail-open (return true → app runs) to prevent silent termination
- Clean stale .restore_request files on primary startup before watching
- Delete existing restore_request before re-creating in sendRestoreRequest
  to avoid FileAlreadyExistsException from stale crash artifacts
- Add unit tests and real multi-process integration tests
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.

Single instance mechanism broken on Macs since version 1.6.0

1 participant