Skip to content

Conversation

@petebacondarwin
Copy link
Contributor

Explicitly destroy all stdio streams (stdin, stdout, stderr, and control pipe) before killing the workerd process in Runtime#dispose(). This ensures file descriptors are properly released before spawning a new process, preventing EBADF errors during rapid restarts.

The original issue was not able to provide a reproduction that we could test so this PR is speculative.

Fixes #11675


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bug fix

A picture of a cute animal (not mandatory, but encouraged)

Explicitly destroy all stdio streams (stdin, stdout, stderr, and control
pipe) before killing the workerd process in Runtime#dispose(). This
ensures file descriptors are properly released before spawning a new
process, preventing EBADF errors during rapid restarts.

Fixes #11675
@changeset-bot
Copy link

changeset-bot bot commented Jan 21, 2026

🦋 Changeset detected

Latest commit: d9ed3ad

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 21, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: d9ed3ad

runtimeProcess.stdin?.destroy();
runtimeProcess.stdout?.destroy();
runtimeProcess.stderr?.destroy();
// The control pipe at stdio[3] is a Readable stream
Copy link
Contributor

Choose a reason for hiding this comment

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

That's not consistent with l335?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess this could be:

Suggested change
// The control pipe at stdio[3] is a Readable stream
// The control pipe at stdio[3] could be a Readable stream. If so also destroy it

});

test("Miniflare: setOptions: can restart workerd multiple times in succession", async () => {
// Regression test for https://github.com/cloudflare/workers-sdk/issues/11675
Copy link
Contributor

@vicb vicb Jan 21, 2026

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think annotations are too noisy for this sort of thing. We don't need this to be displayed in every test run report.

Copy link
Contributor

Choose a reason for hiding this comment

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

https://vitest.dev/guide/test-annotations.html#built-in-reporters
The default reporter prints annotations only if the test has failed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes but I regularly use verbose reporter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And more importantly, this link to the original issue is not needed in the reporter outpiut. If the test fails it is because something has broken that needs fixing. The original issue is only one of the sources for looking into what could be the cause.

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

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

EBADF thrown when restarting workerd on vite server restart

2 participants