Skip to content

[wrangler] fix: handle deleted entry point during hot-reload without unhandled rejection#13838

Open
matingathani wants to merge 5 commits into
cloudflare:mainfrom
matingathani:fix/unhandled-rejection-esbuild-entry-deleted
Open

[wrangler] fix: handle deleted entry point during hot-reload without unhandled rejection#13838
matingathani wants to merge 5 commits into
cloudflare:mainfrom
matingathani:fix/unhandled-rejection-esbuild-entry-deleted

Conversation

@matingathani
Copy link
Copy Markdown
Contributor

Fixes #13122.

During wrangler dev, if the worker entry point is deleted or moved between builds, the readFileSync call inside the updateBundle callback throws synchronously and is promoted to an unhandled promise rejection, crashing the process.

Fix: Wrap the readFileSync call in a try/catch. On failure, log a warning and return the previous bundle unchanged, so the dev session stays alive.


  • Tests
    • Tests included/updated
  • Public documentation
    • Documentation not necessary because: internal dev-mode error handling, no user-facing API change

Copilot AI review requested due to automatic review settings May 7, 2026 00:30
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 7, 2026

🦋 Changeset detected

Latest commit: fa47c9f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@workers-devprod workers-devprod requested review from a team and penalosa and removed request for a team May 7, 2026 00:31
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented May 7, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves wrangler dev hot-reload resilience by preventing a synchronous readFileSync() failure (when the worker entrypoint is deleted/moved between rebuilds) from being promoted into an unhandled promise rejection that crashes the process.

Changes:

  • Wraps readFileSync(previousBundle.path, "utf8") in a try/catch during rebuild updates and logs a warning on failure.
  • Skips applying the rebuild update when the entrypoint can’t be read (intended to keep the dev session alive).
  • Adds a changeset to ship the fix as a patch release.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/wrangler/src/dev/use-esbuild.ts Adds error handling + warning log around reading the previous bundle entrypoint during rebuild updates.
.changeset/fix-unhandled-rejection-esbuild-entry-deleted.md Declares a patch changeset describing the dev hot-reload crash fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/wrangler/src/dev/use-esbuild.ts Outdated
Comment thread packages/wrangler/src/dev/use-esbuild.ts Outdated
Comment thread packages/wrangler/src/dev/use-esbuild.ts
@matingathani
Copy link
Copy Markdown
Contributor Author

@NuroDev @penalosa @dario-piotrowicz — all Copilot review comments have been addressed. This PR is ready for review.

Comment thread packages/wrangler/src/dev/use-esbuild.ts Outdated
Copy link
Copy Markdown
Contributor

@workers-devprod workers-devprod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk May 7, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 7, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13838

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13838

miniflare

npm i https://pkg.pr.new/miniflare@13838

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13838

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13838

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13838

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13838

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13838

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@13838

wrangler

npm i https://pkg.pr.new/wrangler@13838

commit: fa47c9f

@matingathani matingathani force-pushed the fix/unhandled-rejection-esbuild-entry-deleted branch from bfd2ac8 to 9df1c4a Compare May 11, 2026 02:17
@matingathani
Copy link
Copy Markdown
Contributor Author

The Windows CI failure is unrelated to this PR's changes.

What failed: packages/miniflare/test/plugins/browser/index.spec.ts — 9 browser plugin tests timed out or got SyntaxError: Unexpected token 'E', "Error: The"... is not valid JSON from entry.worker.js.

What this PR touches: only packages/wrangler/src/dev/use-esbuild.ts and a changeset file.

This looks like a known flaky Windows browser/CDP test (browser session not starting in time on slow Windows runners). Could a maintainer re-run the failed jobs? 🙏

@matingathani
Copy link
Copy Markdown
Contributor Author

CI failure (Tests, Windows, packages-and-tools) is the same pre-existing miniflare browser plugin flake — browser session times out on the Windows runner. Unrelated to the hot-reload entrypoint fix. Could a maintainer re-run the failed job?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved

Development

Successfully merging this pull request may close these issues.

Unhandled rejection when worker entry point is deleted during rebuild

4 participants