feat: block HTTP requests during active rebuilds via WatchLock#81
Merged
Conversation
cecton
reviewed
Apr 25, 2026
cecton
reviewed
Apr 25, 2026
cecton
added a commit
to rustminded/xtask-watch
that referenced
this pull request
Apr 25, 2026
- Add public `WatchLock` / `WatchLockGuard` types for coordinating rebuilds with external readers (e.g. HTTP handlers) - Add `Watch::lock()` to retrieve the watcher's shared lock handle - `Watch::run()` holds the write lock for the entire duration of each command sequence — readers calling `WatchLock::acquire()` block until the build finishes, including the very first one - Fix race condition: generation counter ensures stale `CommandSucceeded` messages from a killed build are ignored - Document lock lifecycle on `Watch::lock()` and `Watch` struct ## Why Allows consumers such as dev servers to block file-serving while a rebuild is in progress, without serving stale or mid-write artifacts. The lock handle is cloneable and `Send + Sync`, so it composes naturally with threaded HTTP handlers. Related to rustminded/xtask-wasm#81 --------- Co-authored-by: Cecile Tonglet <cecile.tonglet@cecton.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WatchLockfrom the configured watcher before spawning the watch threadWatchLockandWatchLockGuardfromxtask-wasmso consumers don't need a directxtask-watchdependency to name the typesread_headeris intentionally called before acquiring the lock (connections are accepted and headers parsed during a build, reducing response latency once it finishes)Why
Without coordination, a browser refresh mid-rebuild could receive incomplete or inconsistent dist artifacts. Using the shared watcher lock ensures the dev server only serves files once the current build has fully written its output.
Closes #80
Requires rustminded/xtask-watch#34