Skip to content

fix(storage): retry a writer lock that names our own pid (#552) - #557

Merged
ajianaz merged 2 commits into
developfrom
fix/storage-lock-after-drop
Nov 10, 2026
Merged

ajianaz merged 2 commits into
developfrom
fix/storage-lock-after-drop

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

What

lock_writer now retries for up to 150 ms (5 ms steps) when the writer lock is held and the recorded holder is our own pid.

Why

Fixes #552. An flock belongs to the open file description, so a child forked by another thread of the same process (a command, job or hook) briefly holds a duplicate of our lock descriptor until it execs, even with O_CLOEXEC. A reopen right after drop(storage) in that window failed with Locked { holder: <our pid> }. It caused a spurious 409 on POST /sessions {"resume"}, failures in the TUI /resume and /new, and two flaky tole-core tests.

Changes

  • crates/tole-core/src/storage.rs: bounded retry in lock_writer, only for a hold that names our own pid. A holder with another pid still fails at once, and a genuine second open in this process (storage: no cross-process writer exclusion — a second writer corrupts the session file (live repro) #475) still fails after at most the bounded wait. The lock file is re-read from the start on each attempt.
  • crates/tole-core/tests/writer_lock.rs: the probe from the issue as a regression test, plus a test that both real refusals stay (other pid: under 50 ms; same process: bounded).
  • CHANGELOG (Fixed).

Testing

  • Regression test: 6000 create/drop/reopen rounds against three threads spawning children. Before the fix 8 to 12 rounds failed; after, 0 (three runs). Mutation check: setting the retry to 0 makes it fail again.
  • The two flaky tests named in the issue pass under parallel load.
  • cargo fmt, cargo clippy --workspace --all-targets -- -D warnings and cargo test --workspace pass.

Closes #552


Generated by Claude Code

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 89267fe into develop Nov 10, 2026
15 of 16 checks passed
@ajianaz
ajianaz deleted the fix/storage-lock-after-drop branch November 11, 2026 04:10
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.

fix(storage): a fork+exec in another thread makes a reopen after drop fail with Locked

2 participants