Skip to content

[miniflare] Reuse and retire Hyperdrive proxy listeners - #15879

Merged
cjol merged 2 commits into
cloudflare:mainfrom
dawNotPoi:fix/miniflare-hyperdrive-proxy-lifecycle
Oct 7, 2026
Merged

cjol merged 2 commits into
cloudflare:mainfrom
dawNotPoi:fix/miniflare-hyperdrive-proxy-lifecycle

Conversation

@dawNotPoi

@dawNotPoi dawNotPoi commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #15843.

Repeated Miniflare.setOptions() calls created a new Hyperdrive proxy listener for each reload and overwrote the only reference to the previous listener. Those ports stayed open after subsequent updates and could remain open after dispose().

This change reuses a listener when the binding and its connection settings are unchanged. During each configuration update, Miniflare tracks which listeners the new runtime uses. After the runtime accepts the new configuration, it closes listeners not referenced by the assembled services, including changed, removed, SSL-disabled, or duplicate bindings. If assembly or runtime startup fails, it closes only listeners created for that attempt and keeps the previous listeners available. Concurrent requests for the same connection settings share one listener. Closing a retired listener stops new connections while existing connections finish naturally.

The fix lives in Miniflare, so Wrangler, the Vite plugin, and the Vitest plugin share the same lifecycle behavior. No public API or configuration changes are needed.

I claimed the issue and described the approach before development: #15843 (comment)

Regression tests first reproduced the listener growth on unchanged and changed targets, the failed-update leak, and duplicate concurrent listeners. The tests now cover reloads, changed or removed bindings, sslmode=disable, failed updates, disposal, concurrent creation, duplicate binding names across workers, and an existing TCP connection during retirement.

Validation on Node 22.22.1: Miniflare package tests 1,369 passed / 1 skipped; repository pnpm check 207/207 successful; independent review and focused Hyperdrive tests 25/25 passed.


  • 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: this fixes local proxy listener cleanup behind the existing Hyperdrive configuration and changes no public usage.

Note

This is a contribution from an AI agent: Codex, GPT-6 Sol High. The changes were independently reviewed before submission.

@changeset-bot

changeset-bot Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8019ec9

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

This PR includes changesets to release 8 packages
Name Type
miniflare Patch
@cloudflare/deploy-helpers Patch
@cloudflare/pages-shared Patch
@cloudflare/remote-bindings Patch
@cloudflare/runtime-types Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-plugin Patch
wrangler 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

@dawNotPoi

Copy link
Copy Markdown
Contributor Author

@tpmmorris Ready for review. This fixes #15843 by reusing unchanged Hyperdrive proxy listeners and retiring obsolete listeners only after a successful Miniflare configuration update; failed updates preserve the previous listeners. Regression tests cover reloads, changes, removal, disable, rollback, concurrent creation, and existing connections. Miniflare tests passed 1,368/1,368 on Node 22.22.1, repository checks passed 207/207, and an independent focused rerun passed 24/24.

@workers-devprod
workers-devprod requested review from a team and cjol and removed request for a team September 25, 2026 18:39
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/hyperdrive-proxy-lifecycle.md: [@cloudflare/wrangler]
  • packages/miniflare/src/index.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/plugins/hyperdrive/hyperdrive-proxy.ts: [@cloudflare/wrangler]
  • packages/miniflare/test/plugins/hyperdrive/lifecycle.spec.ts: [@cloudflare/wrangler]
  • packages/miniflare/test/plugins/hyperdrive/proxy.spec.ts: [@cloudflare/wrangler]

devin-ai-integration[bot]

This comment was marked as resolved.

@pkg-pr-new

pkg-pr-new Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@15879

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@15879

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@15879

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@15879

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@15879

create-cloudflare

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

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@15879

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@15879

@cloudflare/pages-shared

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

@cloudflare/runtime-types

npm i https://pkg.pr.new/@cloudflare/runtime-types@15879

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@15879

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@15879

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 8019ec9

@dawNotPoi
dawNotPoi force-pushed the fix/miniflare-hyperdrive-proxy-lifecycle branch from ec78241 to 8019ec9 Compare September 28, 2026 06:49
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@workers-devprod workers-devprod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codeowners reviews satisfied

@cjol
cjol merged commit 8de6b3c into cloudflare:main Oct 7, 2026
56 checks passed
mack-erel added a commit to henryj-dev/contribute_cloudflare_workers-sdk that referenced this pull request Oct 9, 2026
main's cloudflare#15879 reworked `HyperdriveProxyController` around a reload
transaction — listeners keyed by binding and target, reused while the
target is unchanged, and retired by `commitUpdate()` once a reload stops
using them — which conflicted with this branch's remote TCP bridge.

Resolved by putting the bridge on the same lifecycle instead of beside
it: `createRemoteTcpBridge()` now keys, reuses and registers its
listener exactly like `createProxyServer()`, so a bridge survives
reloads that leave it unchanged and is retired once its binding is
removed or switched to local — which also closes the "obsolete bridges
remain open" gap Devin raised. Retiring follows main's rule of leaving
already-accepted connections to finish; only `dispose()` still destroys
them, via the connection tracking this branch added, so nothing outlives
the controller. A retired bridge's port is forgotten too, so Node-side
bindings stop handing out a dead address.

One main test assumed same-named bindings in different workers collapse
onto one service. This branch namespaces Hyperdrive services per worker
(005e6ed, from review), so each gets its own listener; the test now
asserts that and that the extra listener still retires. Two tests cover
remote bridge reuse and retirement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
brandhaug added a commit to brandhaug/b2b-saas-starter that referenced this pull request Oct 11, 2026
…lpha (#879)

## pnpm-workspace.yaml (default)

## Dependency Updates

| Package | From | To | Type |
| --- | --- | --- | --- |
| `miniflare` | 5.20261006.0-alpha | 5.20261006.1-alpha | prerelease |

## Release Notes

<details>
<summary><b>miniflare</b> (5.20261006.0-alpha →
5.20261006.1-alpha)</summary>

### Patch Changes

- [#16139](cloudflare/workers-sdk#16139)
[`2d1d563`](cloudflare/workers-sdk@2d1d563)
Thanks [@<!---->cpojer](https://github.com/cpojer)! - Update esbuild to
0.28.2

Align esbuild dependency with tooling using the latest 0.28 patch so
package managers can share one installation instead of downloading a
second native binary.

- [#15939](cloudflare/workers-sdk#15939)
[`e6f7663`](cloudflare/workers-sdk@e6f7663)
Thanks [@<!---->00200200](https://github.com/00200200)! - Fix local
Workflows hitting the timer quota on long runs

Long local workflows no longer fail from timer exhaustion. Step timeout
timers, sleep, waitForEvent, and grace-period waits now cancel their
underlying timers when finished or aborted, instead of remaining until
their original deadlines.

- [#16098](cloudflare/workers-sdk#16098)
[`fe607f9`](cloudflare/workers-sdk@fe607f9)
Thanks [@<!---->dependabot](https://github.com/apps/dependabot)! -
Update dependencies of "miniflare", "wrangler"

  The following dependency versions have been updated:

  | Dependency | From   | To     |
  | ---------- | ------ | ------ |
  | sharp      | 0.35.4 | 0.35.5 |

- [#15879](cloudflare/workers-sdk#15879)
[`8de6b3c`](cloudflare/workers-sdk@8de6b3c)
Thanks [@<!---->dawNotPoi](https://github.com/dawNotPoi)! - Stop
Hyperdrive proxy listeners from accumulating across local development
reloads

Miniflare now reuses a listener when a Hyperdrive binding keeps the same
target and closes listeners no longer used after a configuration update.
Changing or removing a binding, including switching to
`sslmode=disable`, no longer leaves stale listening ports in `wrangler
dev`.

- [#16106](https://github.com/cloud

…[full
notes](https://github.com/cloudflare/workers-sdk/releases/tag/miniflare%405.20261006.1-alpha)

</details>

---
*This PR was auto-generated by
[catalog-update-action](https://github.com/brandhaug/catalog-update-action).*

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

[miniflare] Each setOptions() leaves the previous Hyperdrive proxy servers listening, also after dispose()

3 participants