Repository navigation
Description
What version of Effect is running?
effect 4.0.0 through 4.0.7, and 4.1.0. Related: #9178 (closed by #9182 in 4.1.0), #9460 (4.0.6), #10121.
What happens
Some transports cannot answer a call: an asynchronous serverless invoke, a message queue, a webhook that only acknowledges delivery. A custom RpcClient.Protocol over such a transport sends the request and never writes a reply. discard: true is the obvious way to call through it.
- 4.0.0 – 4.0.7.
client.Tag(payload, { discard: true })returns oncesendfinishes.RpcClient.make'sonFromClientignores thediscardhint, though, and registers an entry{ rpc, context, schemas }. The entry is removed only by the server'sExitor by anInterrupt. Neither comes for a discarded call over this kind of protocol, so the entry, holding the caller's wholeContext, lives as long as the client. This is the case RPC: calls made withdiscard: truestill get a reply #9178 reported. Fix RpcClient retaining requests that fail without a reply #9460 (4.0.6) fixed the related case of failed sends, but not this one. - 4.1.0. After Acknowledge discarded RPC calls before running handlers #9182, a discarded call waits for the server to acknowledge it with an
Exit. On a protocol that never replies, the call never completes. Without a timeout, the caller's fiber and the entry both stay forever. Code that completed in 4.0.x hangs after the upgrade.
The protocol interface has no way to say "this transport does not reply". The docs also do not say that a protocol must acknowledge discarded requests itself.
Reproduction
Public APIs only. The protocol accepts every request and never answers. Each round provides ~10 MB of unique strings in the caller's context.
// node --expose-gc rpc-unanswered-request.mjs discard (or: bun rpc-unanswered-request.mjs discard)
import { randomBytes } from "node:crypto";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Schema from "effect/Schema";
import * as Rpc from "effect/rpc/Rpc";
import * as RpcClient from "effect/rpc/RpcClient";
import * as RpcGroup from "effect/rpc/RpcGroup";
import * as RpcSerialization from "effect/rpc/RpcSerialization";
const collect = () => (globalThis.Bun ? Bun.gc(true) : globalThis.gc());
const heapMB = () => Math.round(process.memoryUsage().heapUsed / 2 ** 20);
const Group = RpcGroup.make(Rpc.make("Record", { payload: { round: Schema.Number } }));
class History extends Context.Service()("History") {}
const OneWay = Layer.effect(
RpcClient.Protocol,
RpcClient.Protocol.make(() =>
Effect.succeed({
send: () => Effect.void,
supportsAck: false,
supportsTransferables: false,
codecFor: RpcSerialization.json.codecFor,
}),
),
);
const call = (client, round) =>
client.Record({ round }, { discard: true }).pipe(
Effect.exit,
Effect.timeoutOption("200 millis"),
Effect.map((exit) => (Option.isNone(exit) ? "still waiting after 200 ms" : exit.value._tag)),
Effect.provideService(History, Array.from({ length: 2000 }, () => randomBytes(2500).toString("hex"))),
);
await Effect.runPromise(
Effect.scoped(
Effect.gen(function* () {
const client = yield* RpcClient.make(Group);
for (let round = 0; round < 6; round++) {
const outcome = yield* call(client, round);
yield* Effect.promise(() => new Promise((resolve) => setTimeout(resolve, 10)));
collect();
console.log(`round ${round}: call ${outcome}, heapUsed ${heapMB()} MB`);
}
}),
).pipe(Effect.provide(OneWay)),
);Expected
The discarded call completes once the request is sent, and the client keeps nothing for it, so heapUsed stays flat.
Actual
heapUsed in MB after each round, with a forced GC:
| effect | Node 22.23.2 | Bun 1.4.4 | the call |
|---|---|---|---|
| 4.0.0 | 25, 35, 45, 54, 64, 73 | 14, 24, 33, 43, 52, 62 | completes |
| 4.0.7 | 24, 34, 43, 53, 63, 72 | 14, 24, 33, 43, 53, 62 | completes |
| 4.1.0 | 15, 15, 15, 15, 16, 16 | 5, 5, 5, 5, 5, 5 | still waiting after 200 ms, every round |
| 4.0.0 with #9460 and the 4.0.x change below | 16, 16, 16, 16, 16, 16 | 4, 4, 4, 4, 4, 4 | completes |
On 4.1.0, the heap is flat only because the repro's timeout interrupts the call, and the interrupt removes the entry. Without the timeout, the first call never returns.
For comparison, a send that fails (Effect.fail(new RpcClientError(...)) from send) leaks the same way on 4.0.0, and is flat on 4.0.7 and 4.1.0 thanks to #9460.
Proposed change
Either of these would let a one-way protocol work:
- Let a protocol declare that it does not reply, for example
supportsReplies: falsenext tosupportsAck.RpcClient.makewould then complete a discarded call oncesendsucceeds, without registering an entry, and reject non-discarded calls on that protocol. - Document that a protocol over a transport that cannot reply must write the acknowledgement itself, a successful
Exitfor the request id, once the transport accepts a discarded request. That is what a one-way protocol can do on 4.1.0 today.
For 4.0.x, the smallest fix is in RpcClient.make: remove the entry of a discarded request once its send is over. On an answering transport, a later Exit finds no entry and is ignored, as it already is in makeNoSerialization.
- onFromClient({ message }) {
+ onFromClient({ message, discard }) {
...
- ) as Effect.Effect<void, RpcClientError>
+ ).pipe(discard ? Effect.ensuring(Effect.sync(() => entries.delete(message.id))) : identity) as Effect.Effect<void, RpcClientError>
Activity
effect-bot commentedon Oct 29, 2026
Thanks for the detailed report and the reproduction.
We're not adding a separate "no replies" mode. The client relies on every request it sends ending with a reply for its id, usually an
Exit. The protocol in the reproduction accepts requests and never replies, so on 4.1.0 the discarded call waits forever, and on 4.0.x the request entry is never removed. The client is behaving as designed; the protocol isn't meeting that contract.A transport that only delivers requests can still meet it on 4.1.0 and later:
discardrequest, write a voidExitfor it. That's the strongest acknowledgement a one-way transport can give.sendwith anRpcClientErrorfor any other request, so calls that expect a result fail immediately instead of hanging.Adapted from your reproduction:
Keep the acknowledgement lazy (
() => writeResponse(...)). Written eagerly, it is recorded as soon assendstarts, so the client stops tracking the call beforedeliverruns and closing the client can no longer interrupt a pending delivery.I checked this against the published
effect@4.1.0and against currentmain:client.Record({ round: 0 }, { discard: true })completes withvoidoncedeliversucceeds, and nothing is kept after the reply.discard, whether unary or stream, fails with anRpcClientError, and nothing is delivered.mainfor the next release.discardmarker, so a protocol can't tell discarded calls apart. There's no maintained 4.0.x release line to fix that on, so please upgrade to 4.1.#10171 documents this contract on
RpcClient.Protocoland on thediscardoption, and #10172 aligns those docs with the pattern above.