Clear tracked RPCs on reconnect (#2000)

This commit is contained in:
Julius Marminge committed 2026-04-13 14:44:53 -07:00
1 parent ccbb9d73ab
commit 5d9636b4d9
2 files changed
+52

No files matched your search

+50
View File
@@ -417,6 +417,56 @@ describe("WsTransport", () => {
await transport.dispose();
}, 5_000);
it("clears slow unary request tracking when the transport reconnects", async () => {
const slowAckThresholdMs = 25;
setSlowRpcAckThresholdMsForTests(slowAckThresholdMs);
const transport = createTransport("ws://localhost:3020");
const requestPromise = transport.request((client) =>
client[WS_METHODS.serverUpsertKeybinding]({
command: "terminal.toggle",
key: "ctrl+k",
}),
);
await waitFor(() => {
expect(sockets).toHaveLength(1);
});
const firstSocket = getSocket();
firstSocket.open();
await waitFor(() => {
expect(firstSocket.sent).toHaveLength(1);
});
const firstRequest = JSON.parse(firstSocket.sent[0] ?? "{}") as { id: string };
await waitFor(() => {
expect(getSlowRpcAckRequests()).toMatchObject([
{
requestId: firstRequest.id,
tag: WS_METHODS.serverUpsertKeybinding,
},
]);
}, 1_000);
void requestPromise.catch(() => undefined);
await transport.reconnect();
expect(getSlowRpcAckRequests()).toEqual([]);
await waitFor(() => {
expect(sockets).toHaveLength(2);
});
const secondSocket = getSocket();
secondSocket.open();
await transport.dispose();
}, 5_000);
it("sends unary RPC requests and resolves successful exits", async () => {
const transport = createTransport("ws://localhost:3020");
+2
View File
@@ -12,6 +12,7 @@ import {
import { RpcClient } from "effect/unstable/rpc";
import { ClientTracingLive } from "../observability/clientTracing";
import { clearAllTrackedRpcRequests } from "./requestLatencyState";
import {
createWsRpcProtocolLayer,
makeWsRpcProtocolClient,
@@ -189,6 +190,7 @@ export class WsTransport {
throw new Error("Transport disposed");
}
clearAllTrackedRpcRequests();
const previousSession = this.session;
this.session = this.createSession();
await this.closeSession(previousSession);