Skip to content

Add cross-session file locking + concurrent build tests#11

Merged
dinkelk merged 2 commits into
masterfrom
feature/cross-session-locking-v2
Mar 11, 2026
Merged

Add cross-session file locking + concurrent build tests#11
dinkelk merged 2 commits into
masterfrom
feature/cross-session-locking-v2

Conversation

@dinkelk

@dinkelk dinkelk commented Mar 10, 2026

Copy link
Copy Markdown
Owner

Two commits:

1. Cross-session file locking

Moves target and database lock files from per-session temp directories (/tmp/redo-<user>/<session>/) to a global location (/tmp/redo-<uid>-locks/).

Before: Each top-level redo invocation used its own REDO_SESSION-scoped lock directory. Two separate redo commands could not coordinate locks on shared targets — they'd both build the same target simultaneously.

After: Lock files are UID-namespaced in /tmp (auto-cleanup on reboot) and shared across all redo sessions for the same user. The flock() mechanism is unchanged — only the directory location moves.

2. Concurrent build tests (test/410-concurrent/)

5 tests exercising cross-session concurrency:

  1. Same target from two processes simultaneously
  2. Overlapping dependency chains with shared deep dep
  3. Stress test: 4 processes building same target
  4. Different targets with shared slow dependency
  5. Rapid-fire rebuild after .do file invalidation

Why

The existing locking only worked for intra-session parallelism (-j flag). When two separate redo processes built overlapping targets, they couldn't see each other's locks. This is a real scenario in CI pipelines, multi-terminal development, and script-driven builds.

dinkelk added 2 commits March 11, 2026 14:32
Move target and database lock files from per-session temp directories
(/tmp/redo-<user>/<session>/) to a global location (/tmp/redo-<uid>-locks/).

Previously, each top-level redo invocation used its own REDO_SESSION-scoped
lock directory, meaning two separate `redo` commands could not coordinate
locks on shared targets. This caused potential races when building the same
target tree from multiple terminals or scripts.

Now lock files are UID-namespaced in /tmp for auto-cleanup on reboot, and
shared across all redo sessions for the same user. The flock() mechanism
is unchanged, only the directory location moves.
Five tests exercising cross-session concurrency:

1. Same target from two processes simultaneously
2. Overlapping dependency chains with shared deep dep
3. Stress test: 4 processes building same target
4. Different targets with shared slow dependency
5. Rapid-fire rebuild after .do file invalidation

Tests use sleep delays to create race windows and verify
output correctness after concurrent builds complete.
@dinkelk
dinkelk force-pushed the feature/cross-session-locking-v2 branch from f487d38 to 860f1f6 Compare March 11, 2026 20:32
@dinkelk dinkelk changed the title feat: cross-session file locking + concurrent build tests Add cross-session file locking + concurrent build tests Mar 11, 2026
@dinkelk
dinkelk merged commit 0d1443c into master Mar 11, 2026
1 check passed
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