Skip to content

Fix RpcServer toHttpEffect lifetime#2162

Draft
wking-io wants to merge 1 commit into
Effect-TS:mainfrom
wking-io:fix-rpc-to-http-effect-lifetime
Draft

Fix RpcServer toHttpEffect lifetime#2162
wking-io wants to merge 1 commit into
Effect-TS:mainfrom
wking-io:fix-rpc-to-http-effect-lifetime

Conversation

@wking-io
Copy link
Copy Markdown
Contributor

Summary

  • Detach the toHttpEffect server loop from the ambient scope so the returned HTTP effect can be used after construction scope cleanup.
  • Keep non-framed HTTP clients registered until the server loop writes Exit and ClientEnd, allowing Queue.collect to finish.
  • Add a regression test for non-framed JSON-RPC where toHttpEffect is constructed in a short-lived scope before handling a request.

Context

A downstream Cloudflare Worker setup using Alchemy constructs RpcServer.toHttpEffect(...) for RpcSerialization.jsonRpc(). After fixing the separate finalizer requestIds TDZ crash, the official adapter decoded the request and sent EOF, then hung in the non-framed Queue.collect path until workerd canceled the request. Runtime logs showed the server loop never emitted Exit/ClientEnd before the ambient request scope finalized.

This change makes toHttpEffect own the server loop lifetime independently of the construction scope and avoids treating non-framed one-shot HTTP requests as disconnects before their collected response is produced.

Test plan

  • pnpm vitest run packages/effect/test/rpc/RpcServer.test.ts
  • pnpm --filter effect check

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 11, 2026

⚠️ No Changeset found

Latest commit: 94d51c8

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

@wking-io wking-io marked this pull request as draft May 11, 2026 17:09
Ping: () => Effect.succeed("pong")
})),
Effect.provideService(RpcSerialization.RpcSerialization, RpcSerialization.jsonRpc()),
Effect.scoped
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This Effect.scoped will shutdown the server immediately.

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.

2 participants