Skip to content

Add RpcServer onDisconnect option - #9688

Merged
tim-smart merged 7 commits into
v4/next-minorfrom
fix/rpc-server-on-disconnect
Oct 22, 2026
Merged

tim-smart merged 7 commits into
v4/next-minorfrom
fix/rpc-server-on-disconnect

Conversation

@effect-bot

Copy link
Copy Markdown
Contributor

Summary

RpcServer.make takes from Protocol.disconnects, a single-consumer queue, to interrupt a disconnected client's in-flight requests. An application that takes from the same queue to observe disconnects can steal a notification, which stops the server from cleaning up that client.

This adds an optional onDisconnect(clientId) callback to RpcServer.make. It is also accepted by layer, layerHttp, toHttpEffect and toHttpEffectWebsocket, which pass it through to make.

  • The callback runs after the server has handled each disconnect.
  • Failures and defects in the callback are logged and ignored, so the disconnect loop keeps running.
  • Protocol, the queue semantics and transport implementations are unchanged. Without the option, behaviour is the same as before.

Tests

  • New regression test in packages/effect/test/rpc/RpcServer.test.ts.
  • vitest run test/rpc: 109 tests pass.
  • pnpm check and pnpm lint pass.

Closes EFF-2696
Closes #8461

@changeset-bot

changeset-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: da447d0

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

This PR includes changesets to release 33 packages
Name Type
effect Minor
@effect/opentelemetry Minor
@effect/vitest Minor
@effect/ai-anthropic Minor
@effect/ai-cloudflare Minor
@effect/ai-openai-compat Minor
@effect/ai-openai Minor
@effect/ai-openrouter Minor
@effect/ai-typesafe Minor
@effect/atom-react Minor
@effect/atom-solid Minor
@effect/atom-vue Minor
@effect/platform-browser Minor
@effect/platform-bun Minor
@effect/platform-deno Minor
@effect/platform-node-shared Minor
@effect/platform-node Minor
@effect/sql-clickhouse Minor
@effect/sql-d1 Minor
@effect/sql-libsql Minor
@effect/sql-mssql Minor
@effect/sql-mysql2 Minor
@effect/sql-pg Minor
@effect/sql-pglite Minor
@effect/sql-sqlite-bun Minor
@effect/sql-sqlite-do Minor
@effect/sql-sqlite-node Minor
@effect/sql-sqlite-react-native Minor
@effect/sql-sqlite-wasm Minor
@effect/docgen Minor
@effect/doctest Minor
@effect/graphql-generator Minor
@effect/openapi-generator Minor

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

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.18 KB 39.18 KB 0.00 KB (0.00%)
basic.ts 7.08 KB 7.08 KB 0.00 KB (0.00%)
batching.ts 10.95 KB 10.95 KB 0.00 KB (0.00%)
brand.ts 6.71 KB 6.71 KB 0.00 KB (0.00%)
cache.ts 11.39 KB 11.39 KB 0.00 KB (0.00%)
config.ts 22.55 KB 22.55 KB 0.00 KB (0.00%)
differ.ts 21.70 KB 21.70 KB 0.00 KB (0.00%)
http-client.ts 26.51 KB 26.51 KB 0.00 KB (0.00%)
http-router.ts 35.74 KB 35.74 KB 0.00 KB (0.00%)
logger.ts 11.76 KB 11.76 KB 0.00 KB (0.00%)
metric.ts 9.32 KB 9.32 KB 0.00 KB (0.00%)
optic.ts 6.93 KB 6.93 KB 0.00 KB (0.00%)
pubsub.ts 15.82 KB 15.82 KB 0.00 KB (0.00%)
queue.ts 12.64 KB 12.64 KB 0.00 KB (0.00%)
schedule.ts 11.63 KB 11.63 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 13.89 KB 13.89 KB 0.00 KB (0.00%)
schema-binary.ts 40.70 KB 40.70 KB 0.00 KB (0.00%)
schema-class.ts 21.40 KB 21.40 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 32.39 KB 32.39 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.59 KB 27.59 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.13 KB 15.13 KB 0.00 KB (0.00%)
schema-string.ts 12.14 KB 12.14 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.06 KB 16.06 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.70 KB 38.70 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 25.79 KB 25.79 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.64 KB 20.64 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 20.81 KB 20.81 KB 0.00 KB (0.00%)
schema-toFormatter.ts 20.92 KB 20.92 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 25.51 KB 25.51 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 20.91 KB 20.91 KB 0.00 KB (0.00%)
schema.ts 20.59 KB 20.59 KB 0.00 KB (0.00%)
stm.ts 13.95 KB 13.95 KB 0.00 KB (0.00%)
stream.ts 10.19 KB 10.19 KB 0.00 KB (0.00%)

Comment thread packages/effect/src/rpc/RpcServer.ts Outdated
Effect.andThen(
server.disconnect(clientId),
Effect.ignoreCause(Effect.suspend(() => onDisconnect(clientId)), {
log: true,

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.

This can use the new "Unhandled" log level

@effect-bot
effect-bot force-pushed the fix/rpc-server-on-disconnect branch from ae85ca8 to 795dd25 Compare October 21, 2026 20:39
@effect-bot
effect-bot changed the base branch from main to v4/next-minor October 21, 2026 20:39
@effect-bot
effect-bot force-pushed the fix/rpc-server-on-disconnect branch 2 times, most recently from b8add79 to bc6e7ff Compare October 21, 2026 20:52
@tim-smart
tim-smart force-pushed the v4/next-minor branch 4 times, most recently from 8e6e2e0 to 005c3dd Compare October 21, 2026 22:39
@effect-bot
effect-bot force-pushed the v4/next-minor branch 6 times, most recently from 17383ae to 1c516c1 Compare October 21, 2026 23:20
@effect-bot
effect-bot force-pushed the fix/rpc-server-on-disconnect branch from bc6e7ff to 09586c0 Compare October 21, 2026 23:22
@effect-bot
effect-bot force-pushed the fix/rpc-server-on-disconnect branch from 09586c0 to a89fa6f Compare October 21, 2026 23:23
@effect-bot
effect-bot force-pushed the fix/rpc-server-on-disconnect branch from a89fa6f to 3cacd9c Compare October 21, 2026 23:24
@effect-bot
effect-bot force-pushed the fix/rpc-server-on-disconnect branch from 3cacd9c to 8608934 Compare October 21, 2026 23:25
@effect-bot
effect-bot force-pushed the fix/rpc-server-on-disconnect branch from 8608934 to 4892710 Compare October 21, 2026 23:26
@effect-bot
effect-bot force-pushed the fix/rpc-server-on-disconnect branch from 4892710 to 6e6dfef Compare October 21, 2026 23:28
@effect-bot
effect-bot force-pushed the fix/rpc-server-on-disconnect branch from 6e6dfef to bc8ff1e Compare October 21, 2026 23:32
@effect-bot
effect-bot force-pushed the fix/rpc-server-on-disconnect branch from 2095890 to da447d0 Compare October 22, 2026 00:01
@tim-smart
tim-smart merged commit 0355d6e into v4/next-minor Oct 22, 2026
9 checks passed
@effect-bot effect-bot mentioned this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit to devangpratap/effect that referenced this pull request Oct 22, 2026
tim-smart pushed a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
tim-smart pushed a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
tim-smart pushed a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
effect-bot added a commit that referenced this pull request Oct 22, 2026
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.

RpcServer disconnects cannot be observed without competing with cleanup

2 participants