Skip to content

[miniflare] Make temp directory cleanup best-effort in dispose()#13078

Merged
penalosa merged 2 commits intomainfrom
penalosa/vitest-10511
Mar 30, 2026
Merged

[miniflare] Make temp directory cleanup best-effort in dispose()#13078
penalosa merged 2 commits intomainfrom
penalosa/vitest-10511

Conversation

@penalosa
Copy link
Copy Markdown
Contributor

@penalosa penalosa commented Mar 26, 2026

Fixes #10511.

On Windows, workerd may not release file handles immediately after Runtime#dispose() returns. When Miniflare#dispose() then tries to remove the temp directory, fs.promises.rm fails with EBUSY — and because this isn't caught, the error propagates to the caller (e.g. vitest-pool-workers), producing noisy errors in test output.

The temp directory lives in os.tmpdir(), so the OS will clean it up eventually. This makes the async cleanup path best-effort — matching the pattern the synchronous exit hook already uses.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because: this is a Windows-specific error handling change — the cleanup itself is unchanged, it just no longer throws on failure
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal behaviour change

Open with Devin

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 26, 2026

🦋 Changeset detected

Latest commit: 2e0ee78

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

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

✅ All changesets look good

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 26, 2026

The change is clean and correct. Let me verify my understanding:

  1. The synchronous exit hook (line 1067-1070) already catches errors and logs them at debug level.
  2. The async dispose() method now wraps removeDir in a try/catch too, but silently swallows the error (empty catch {}).

The only minor observation is that the sync exit hook logs the error at debug level (this.#log.debug(...)) while the async path silently swallows it. However, this is a pragmatic choice — the PR description explicitly notes this is about suppressing noisy errors, and the context in dispose() is that cleanup is already happening. The empty catch is defensible here since:

  • The temp directory is in os.tmpdir() and will be cleaned up by the OS.
  • The error is expected (EBUSY on Windows) and not indicative of a real problem.
  • Adding a debug log would be nice for consistency but isn't actionable.

The changeset is properly formatted as a patch for miniflare, and the description is clear.

This is a straightforward, well-motivated fix. No logic bugs, no security issues, no backward compatibility concerns.

LGTM

github run

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 26, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

wrangler

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

commit: 2e0ee78

@penalosa penalosa marked this pull request as ready for review March 27, 2026 00:31
@penalosa penalosa requested a review from a team as a code owner March 27, 2026 00:31
@penalosa penalosa requested a review from NuroDev March 27, 2026 00:31
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 27, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

Comment thread packages/miniflare/src/index.ts Outdated
@github-project-automation github-project-automation bot moved this from Untriaged to In Review in workers-sdk Mar 30, 2026
@github-project-automation github-project-automation bot moved this from In Review to Approved in workers-sdk Mar 30, 2026
@penalosa penalosa merged commit 9282493 into main Mar 30, 2026
51 of 52 checks passed
@penalosa penalosa deleted the penalosa/vitest-10511 branch March 30, 2026 13:57
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Vitest-pool-workers: failed to remove cache objects

3 participants