Skip to content

fix: prevent rebuild hang#31

Closed
hardfist wants to merge 1 commit intomainfrom
fix/rebuild-hang
Closed

fix: prevent rebuild hang#31
hardfist wants to merge 1 commit intomainfrom
fix/rebuild-hang

Conversation

@hardfist
Copy link
Copy Markdown
Contributor

@hardfist hardfist commented Apr 27, 2026

Root Cause

Browser instrumentation narrowed the hang to the second compile inside a reused bundler worker. The first request completes, but on rebuild the worker reaches rspack(options, callback) and the callback never fires, so the main thread keeps waiting and the UI remains on Bundling....

The trigger is the shared @rspack/browser builtinMemFs.volume.reset() call in the reused worker. In controlled browser runs:

  • original path with volume.reset() reaches core rspack start on request 1 and never logs the callback
  • explicit compiler.run() without compiler.close() still hangs when volume.reset() is kept, so compiler.close() is not the root cause
  • keeping the original rspack(options, callback) path but skipping volume.reset() lets request 1 finish normally in the same worker

That points to the global in-worker memfs state used by @rspack/browser: resetting the shared volume after one compile can wedge the next native build. A fresh worker avoids reusing that corrupted shared runtime/memfs state.

Summary

  • terminate the current bundler worker before starting a new bundle request
  • reject any pending request as superseded so stale rebuilds do not keep UI state alive
  • create a fresh worker for the next compile, avoiding reuse of the @rspack/browser worker state after memfs reset

Verification

  • Browser: clean Chrome profile at http://127.0.0.1:3000/; initial build completed, then 6 rapid real keyboard edits in Monaco briefly showed Bundling... and recovered to 173ms with output present
  • Root-cause browser instrumentation:
    • with volume.reset(): request 1 reached core rspack start and did not callback within 10s
    • with compiler.run() no-close and volume.reset(): request 1 reached core compiler.run start no-close and did not callback within 10s
    • with original rspack(options, callback) and reset skipped: request 1 logged core rspack callback ok and bundle done 1, UI recovered to 78ms
  • pnpm lint:check
  • pnpm format:check
  • pnpm build

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 27, 2026

Deploying rspack-playground with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9d6f111
Status: ✅  Deploy successful!
Preview URL: https://9bf04347.rspack-playground.pages.dev
Branch Preview URL: https://fix-rebuild-hang.rspack-playground.pages.dev

View logs

@CPunisher
Copy link
Copy Markdown
Collaborator

close in favor of a8a5d89

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.

2 participants