Skip to content

fix(test): extend cloudflare workers retry to cover full request cycle#2079

Open
Zelys-DFKH wants to merge 2 commits into
modelcontextprotocol:mainfrom
Zelys-DFKH:fix/cloudflare-workers-node20-flaky
Open

fix(test): extend cloudflare workers retry to cover full request cycle#2079
Zelys-DFKH wants to merge 2 commits into
modelcontextprotocol:mainfrom
Zelys-DFKH:fix/cloudflare-workers-node20-flaky

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

Found this while digging into the CI failures on #2026. The Cloudflare Workers test has been flaky on Node 20 with Error: Network connection lost.

Root cause

Wrangler/miniflare reports "Ready" before it can serve all request types reliably. The initialize handshake (client.connect()) goes through, but the subsequent client.callTool() can still fail.

Commit 5a2c8a6 added a retry loop for this, but it only covered connect(). A successful connect followed by a failing callTool() had no retry path.

The fix

The retry loop now wraps the full interaction: connect, callTool, assertion, and close. Any failure cleans up the client and retries with a 1-second backoff, up to 5 attempts. The 30s test timeout is unchanged.

Why it's separate from #2026

#2026 kept hitting this same failure even though its change (44 lines in packages/middleware/node) has nothing to do with the Cloudflare test. Splitting them out makes both cleaner to review. Once this lands, #2026 can rebase onto main and the Node 20 run should pass.

Wrangler on Node 20 accepts the initialize handshake before it can reliably
handle subsequent requests. The previous retry loop only wrapped connect(),
so a successful connect followed by a failed callTool() still caused the
test to fail. Extend the loop to retry the full interaction (connect +
callTool + assertion) and close the client on each failed attempt before
retrying.
@Zelys-DFKH Zelys-DFKH requested a review from a team as a code owner May 12, 2026 23:21
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 12, 2026

⚠️ No Changeset found

Latest commit: 7654565

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 12, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2079

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2079

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2079

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2079

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2079

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2079

commit: 7654565

@Zelys-DFKH
Copy link
Copy Markdown
Author

All checks passing, including Node 20. Ready for review whenever you get a chance.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant