Skip to content

feat: block HTTP requests during active rebuilds via WatchLock#81

Merged
cecton merged 10 commits into
mainfrom
wait-for-build-to-finish
Apr 25, 2026
Merged

feat: block HTTP requests during active rebuilds via WatchLock#81
cecton merged 10 commits into
mainfrom
wait-for-build-to-finish

Conversation

@yozhgoor
Copy link
Copy Markdown
Member

@yozhgoor yozhgoor commented Apr 23, 2026

Summary

  • Obtain the shared WatchLock from the configured watcher before spawning the watch thread
  • Pass the lock into the HTTP serving loop
  • Acquire a read guard per request, after parsing the header, so file reads cannot race with rebuild writes
  • Re-export WatchLock and WatchLockGuard from xtask-wasm so consumers don't need a direct xtask-watch dependency to name the types
  • Document why read_header is 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

@yozhgoor yozhgoor changed the title Block requests until active rebuilds finish fix(dev-server): block requests until active rebuilds finish Apr 23, 2026
@yozhgoor yozhgoor changed the title fix(dev-server): block requests until active rebuilds finish fix(dev-server): coordinate rebuilds and request serving with shared WatchLock Apr 24, 2026
@yozhgoor yozhgoor changed the title fix(dev-server): coordinate rebuilds and request serving with shared WatchLock fix(dev-server): wait for rebuild-safe reads with WatchLock Apr 24, 2026
Comment thread src/dev_server.rs
Comment thread src/dev_server.rs
@cecton cecton changed the title fix(dev-server): wait for rebuild-safe reads with WatchLock Block HTTP requests during rebuilds using WatchLock Apr 25, 2026
@cecton cecton changed the title Block HTTP requests during rebuilds using WatchLock feat: block HTTP requests during active rebuilds via WatchLock 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>
@cecton cecton marked this pull request as ready for review April 25, 2026 16:45
@cecton cecton merged commit ea887d5 into main Apr 25, 2026
7 checks passed
@cecton cecton deleted the wait-for-build-to-finish branch April 25, 2026 16:49
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.

Make the incoming connections hang while waiting for the build to finish

2 participants