Skip to content

Conversation

@petebacondarwin
Copy link
Contributor

@petebacondarwin petebacondarwin commented Dec 15, 2025

The Miniflare unit tests flake fairly often on Windows (and occasionally on other OSes). The errors are a bit difficult to debug because Ava only renders "Fetch failed" and not the cause that contains the actual useful info.

Errors

The patch to the concordance library exposes the cause for these errors, such as:

Caused by: Error: write ECONNABORTED␊
miniflare:test:ci:         at afterWriteDispatched (node:internal/stream_base_commons:161:15)␊
miniflare:test:ci:         at writeGeneric (node:internal/stream_base_commons:152:3)␊
miniflare:test:ci:         at Socket._writeGeneric (node:net:958:11)␊
miniflare:test:ci:         at Socket._write (node:net:970:8)␊
miniflare:test:ci:         at writeOrBuffer (node:internal/streams/writable:572:12)␊
miniflare:test:ci:         at _write (node:internal/streams/writable:501:10)␊
miniflare:test:ci:         at Writable.write (node:internal/streams/writable:510:10)␊
miniflare:test:ci:         at AsyncWriter.end (D:\\a\\workers-sdk\\workers-sdk\\node_modules\\.pnpm\\[email protected]\\node_modules\\undici\\lib\\dispatcher\\client-h1.js:1569:14)␊
miniflare:test:ci:         at writeIterable (D:\\a\\workers-sdk\\workers-sdk\\node_modules\\.pnpm\\[email protected]\\node_modules\\undici\\lib\\dispatcher\\client-h1.js:1438:12)␊

Diagnosis

This can be caused by a race condition between Undici's Keep-Alive mechanism and the Miniflare/Workerd server.

  • Undici keeps the TCP connection open (Keep-Alive) after a request finishes, hoping to reuse it for the next test to save time.
  • The server (Miniflare) decides to close the connection (perhaps due to an idle timeout, which happens faster on constrained Windows CI runners).
  • Undici doesn't know the connection is dead yet. It attempts to write a new request to that existing socket (writeGeneric -> Socket._write).
  • The OS realizes the pipe is broken during the write operation and throws ECONNABORTED.

Fix

The fix is to prevent Undici from trying to keep the connection alive.

  • One way is to add a Connection: close header to the request to force undici to use a new connection for each request. But this felt a bit invasive on the request (and also this header is disallowed for HTTP.
  • Instead we are configuring the Undici dispatche with reset: true which has the same effect of preventing Undici from trying to keep the connection alive. See docs here.

Extras

In addition to the main fix, this PR also quietens/silences a lot of the other miniflare tests that were dumping unnecessary and distracting logs into the test output.


  • Tests
    • Tests included/updated
    • Tests not necessary because: covered by current tests
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: test flake improvements
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because: test flake improvement is not a bug fix

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

@changeset-bot
Copy link

changeset-bot bot commented Dec 15, 2025

🦋 Changeset detected

Latest commit: eb10e46

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-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Dec 15, 2025
@petebacondarwin petebacondarwin force-pushed the pbd/miniflare/windows-fetch-failed branch 2 times, most recently from 479b2bb to f557e60 Compare December 15, 2025 14:26
@petebacondarwin petebacondarwin changed the title Pbd/miniflare/windows fetch failed Improve miniflare test stability Dec 15, 2025
@petebacondarwin petebacondarwin force-pushed the pbd/miniflare/windows-fetch-failed branch 2 times, most recently from 4134d07 to 688b106 Compare December 16, 2025 13:48
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 16, 2025

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: eb10e46

@petebacondarwin petebacondarwin force-pushed the pbd/miniflare/windows-fetch-failed branch 6 times, most recently from 41d5d16 to 574eab3 Compare December 17, 2025 14:02
@claude
Copy link
Contributor

claude bot commented Dec 17, 2025

Claude finished @petebacondarwin's task —— View job


Changeset Review

All changesets look good

The changeset .changeset/floppy-jobs-shout.md follows all guidelines:

  • Correct version type (patch for bug fix)
  • Clear description of the symptom and fix
  • No forbidden markdown headers
  • Proper formatting

@petebacondarwin petebacondarwin force-pushed the pbd/miniflare/windows-fetch-failed branch 3 times, most recently from 8e1ec64 to 8cad69f Compare December 17, 2025 19:41
@petebacondarwin petebacondarwin marked this pull request as ready for review December 18, 2025 10:36
@petebacondarwin petebacondarwin requested review from a team as code owners December 18, 2025 10:36
@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Dec 18, 2025
@petebacondarwin
Copy link
Contributor Author

Oops I forgot to remove the "blasting Windows" commit.

@petebacondarwin petebacondarwin force-pushed the pbd/miniflare/windows-fetch-failed branch 3 times, most recently from cf04605 to a198713 Compare December 18, 2025 13:54
@petebacondarwin petebacondarwin force-pushed the pbd/miniflare/windows-fetch-failed branch from a198713 to eb10e46 Compare December 18, 2025 14:09
@petebacondarwin petebacondarwin merged commit 8eede3f into main Dec 18, 2025
43 of 46 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Dec 18, 2025
@petebacondarwin petebacondarwin deleted the pbd/miniflare/windows-fetch-failed branch December 18, 2025 14:59
AmirSa12 pushed a commit to AmirSa12/workers-sdk that referenced this pull request Jan 5, 2026
* update to latest ava

* Display error `cause` in Miniflare tests

* hide unwanted logging from Miniflare browser plugin tests

* quieten Miniflare secrets-store plugin tests

* quieten Miniflare Durable Object plugin tests

* quieten other Miniflare tests

* Retry removing the Browser Session temp directory

* Give the Miniflare browser plugin tests a bit longer to complete

These tests will need to download the Chrome browser in the background, which can take quite a few seconds sometimes.

* silence Miniflare pipeline plugin tests

* Silence Miniflare unsafe plugin tests

* don't run miniflare tests files concurrently to flakes

In particular the dev-registry tests appear to be particularly sensitive
to concurrency issues, likely due to shared ports/sockets.

* run the Miniflare dev-registry tests in series (rather than parallel)

* fix typo

* quieten unwanted logging from Miniflare dev-registry tests

* no keep-alive

* add changeset

* no keep-alive

* fix changeset

* fix lockfile

* fix changeset (again)

* mark Miniflare browser tests as flaky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants