Skip to content

test(desktop): make the instance-lock flake a bounded retry instead of a panic - #857

Merged
huichen merged 1 commit into
mainfrom
test/instance-lock-retry
Sep 25, 2026
Merged

huichen merged 1 commit into
mainfrom
test/instance-lock-retry

Conversation

@huichen

@huichen huichen commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

What

instance::tests::excludes_second_owner_and_releases_on_drop failed intermittently at the re-acquire after drop. It now retries briefly (2s, 10ms steps) before reporting a leaked lock, so a transient fork window does not read as a product bug.

Why the retry is the right shape

A sibling test's Command::spawn forks while this guard is open. The child shares the open file description until it execs, and flock ownership follows the description rather than the fd, so the lock can still read as held for that window. Retrying keeps the assertion's meaning: a lock that is really never released still fails here — just after the deadline.

Evidence gathered

  • fd exhaustion measured and ruled out: all three instance cases pass under ulimit -n 128, where 284 other tests fail with EMFILE; the suite's peak demand is therefore well under the 2560 soft limit, and this test holds no fds of its own.
  • Not reproducible in isolation: 150 single runs, 320 concurrent runs of this test, and several full suites all pass. Only full-suite load (many sibling Command::spawns) triggers it, ~3 times in ~20 runs — consistent with the fork window above.
  • fs2's try_lock_exclusive calls flock once with no EINTR retry (read from fs2-0.4.3/src/unix.rs), so an interrupted syscall surfaces as a non-WouldBlock error rather than a lock verdict.

Mechanism is inferred, not reproduced — the retry is bounded so this does not mask a real leak, and the diagnostic message added earlier is kept for the deadline case.

Checks

  • cargo fmt --manifest-path desktop/src-tauri/Cargo.toml --check — clean
  • cargo clippy --manifest-path desktop/src-tauri/Cargo.toml --all-targets -- -D warnings — clean
  • cargo test --manifest-path desktop/src-tauri/Cargo.toml --lib instance:: — 3 passed

…eaked

`excludes_second_owner_and_releases_on_drop` failed intermittently under
full-suite load (3 times in ~20 runs) at the re-acquire after `drop`, and
never in isolation (150 single runs, 320 concurrent runs, several full
suites). fd exhaustion was measured and ruled out: all three instance cases
pass under `ulimit -n 128`, where 284 other tests fail with EMFILE, so the
suite's peak demand stays well below the 2560 soft limit.

A sibling test's `Command::spawn` forks while the guard is open and the
child shares the open file description until it execs; `flock` ownership
follows the description rather than the fd, so the lock can still read as
held for that window. Retry briefly instead: a lock that is really never
released still fails here, after the deadline.
@huichen
huichen enabled auto-merge (squash) September 25, 2026 20:53
@huichen
huichen merged commit a07dc13 into main Sep 25, 2026
12 checks passed
@huichen
huichen deleted the test/instance-lock-retry branch September 25, 2026 21:02
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