Repository navigation
[miniflare] Reuse and retire Hyperdrive proxy listeners - #15879
Conversation
🦋 Changeset detectedLatest commit: 8019ec9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
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 |
|
@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. |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/codemods
@cloudflare/config
@cloudflare/containers-shared
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/runtime-types
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-plugin
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
ec78241 to
8019ec9
Compare
|
Codeowners approval required for this PR:
Show detailed file reviewers |
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
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]>
…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>
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 afterdispose().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 check207/207 successful; independent review and focused Hyperdrive tests 25/25 passed.Note
This is a contribution from an AI agent: Codex, GPT-6 Sol High. The changes were independently reviewed before submission.