Skip to content

Commit f5ecca4

Browse files
Clear tracked RPCs on reconnect (#2000)
1 parent cadd708 commit f5ecca4

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

apps/web/src/rpc/wsTransport.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,56 @@ describe("WsTransport", () => {
417417
await transport.dispose();
418418
}, 5_000);
419419

420+
it("clears slow unary request tracking when the transport reconnects", async () => {
421+
const slowAckThresholdMs = 25;
422+
setSlowRpcAckThresholdMsForTests(slowAckThresholdMs);
423+
const transport = createTransport("ws://localhost:3020");
424+
425+
const requestPromise = transport.request((client) =>
426+
client[WS_METHODS.serverUpsertKeybinding]({
427+
command: "terminal.toggle",
428+
key: "ctrl+k",
429+
}),
430+
);
431+
432+
await waitFor(() => {
433+
expect(sockets).toHaveLength(1);
434+
});
435+
436+
const firstSocket = getSocket();
437+
firstSocket.open();
438+
439+
await waitFor(() => {
440+
expect(firstSocket.sent).toHaveLength(1);
441+
});
442+
443+
const firstRequest = JSON.parse(firstSocket.sent[0] ?? "{}") as { id: string };
444+
445+
await waitFor(() => {
446+
expect(getSlowRpcAckRequests()).toMatchObject([
447+
{
448+
requestId: firstRequest.id,
449+
tag: WS_METHODS.serverUpsertKeybinding,
450+
},
451+
]);
452+
}, 1_000);
453+
454+
void requestPromise.catch(() => undefined);
455+
456+
await transport.reconnect();
457+
458+
expect(getSlowRpcAckRequests()).toEqual([]);
459+
460+
await waitFor(() => {
461+
expect(sockets).toHaveLength(2);
462+
});
463+
464+
const secondSocket = getSocket();
465+
secondSocket.open();
466+
467+
await transport.dispose();
468+
}, 5_000);
469+
420470
it("sends unary RPC requests and resolves successful exits", async () => {
421471
const transport = createTransport("ws://localhost:3020");
422472

apps/web/src/rpc/wsTransport.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { RpcClient } from "effect/unstable/rpc";
1313

1414
import { ClientTracingLive } from "../observability/clientTracing";
15+
import { clearAllTrackedRpcRequests } from "./requestLatencyState";
1516
import {
1617
createWsRpcProtocolLayer,
1718
makeWsRpcProtocolClient,
@@ -189,6 +190,7 @@ export class WsTransport {
189190
throw new Error("Transport disposed");
190191
}
191192

193+
clearAllTrackedRpcRequests();
192194
const previousSession = this.session;
193195
this.session = this.createSession();
194196
await this.closeSession(previousSession);

0 commit comments

Comments
 (0)