[miniflare] Lazily initialize remote binding RPC sessions - #15432
Open
razethion wants to merge 2 commits into
Open
[miniflare] Lazily initialize remote binding RPC sessions#15432razethion wants to merge 2 commits into
razethion wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 7c17adf 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 |
workers-devprod
requested review from
a team and
dario-piotrowicz
and removed request for
a team
August 30, 2026 18:24
Contributor
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/codemods
@cloudflare/config
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-plugin
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15351.
Remote bindings use two paths through Miniflare's shared proxy client:
fetch()requests use HTTP.The proxy client previously created the RPC session eagerly in its constructor. This happened even for fetch-only bindings such as D1 and R2. Their successful requests continued through HTTP, while the unused RPC session could fail later and emit delayed
internal error; reference = ...messages.This change creates and caches the RPC session only when an RPC method is called. Fetch-only bindings therefore no longer open an unrelated WebSocket connection. RPC bindings continue to use one shared session when needed.
Investigation
RPC support for remote bindings was introduced in #10249. The intended design was to keep methods implemented by the proxy worker, particularly
fetch(), on their direct path and forward other methods through an RPC stub. The original review discussion notes that direct fetch requests were intentionally kept outside JSRPC because that path is more efficient.However, the fallback RPC stub was created before the proxy knew whether it would be used. #10724 later replaced the original JSRPC implementation with Cap'n Web while preserving this eager session lifecycle.
Simply delaying initialization until an unknown property is accessed is not sufficient because workerd probes optional
WorkerEntrypointhandlers during startup. The proxy now returns a deferred method for unknown properties and initializes the RPC session only if that method is invoked.This explains why affected D1 requests still returned
200: the request used the HTTP path successfully, while the separate unused RPC session produced the delayed errors.Validation
The new Miniflare tests verify that:
A packaged alpha build was also installed in the affected application and tested with the original remote D1 reproduction. The delayed internal-error flood no longer occurred.