Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions apps/web/src/rpc/requestLatencyState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Atom } from "effect/unstable/reactivity";

import { appAtomRegistry } from "./atomRegistry";

export const SLOW_RPC_ACK_THRESHOLD_MS = 2_500;
export const SLOW_RPC_ACK_THRESHOLD_MS = 15_000;
export const MAX_TRACKED_RPC_ACK_REQUESTS = 256;
let slowRpcAckThresholdMs = SLOW_RPC_ACK_THRESHOLD_MS;

export interface SlowRpcAckRequest {
readonly requestId: string;
Expand Down Expand Up @@ -56,12 +57,12 @@ export function trackRpcRequestSent(requestId: string, tag: string): void {
startedAt: new Date(startedAtMs).toISOString(),
startedAtMs,
tag,
thresholdMs: SLOW_RPC_ACK_THRESHOLD_MS,
thresholdMs: slowRpcAckThresholdMs,
};
const timeoutId = setTimeout(() => {
pendingRpcAckRequests.delete(requestId);
appendSlowRpcAckRequest(request);
}, SLOW_RPC_ACK_THRESHOLD_MS);
}, slowRpcAckThresholdMs);

pendingRpcAckRequests.set(requestId, {
request,
Expand Down Expand Up @@ -119,9 +120,14 @@ function evictOldestPendingRpcRequestIfNeeded(): void {
}

export function resetRequestLatencyStateForTests(): void {
slowRpcAckThresholdMs = SLOW_RPC_ACK_THRESHOLD_MS;
clearAllTrackedRpcRequests();
}

export function setSlowRpcAckThresholdMsForTests(thresholdMs: number): void {
slowRpcAckThresholdMs = thresholdMs;
}

export function useSlowRpcAckRequests(): ReadonlyArray<SlowRpcAckRequest> {
return useAtomValue(slowRpcAckRequestsAtom);
}
12 changes: 9 additions & 3 deletions apps/web/src/wsTransport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import {
__resetClientTracingForTests,
configureClientTracing,
} from "./observability/clientTracing";
import { getSlowRpcAckRequests, resetRequestLatencyStateForTests } from "./rpc/requestLatencyState";
import {
getSlowRpcAckRequests,
resetRequestLatencyStateForTests,
setSlowRpcAckThresholdMsForTests,
} from "./rpc/requestLatencyState";
import {
getWsConnectionStatus,
getWsConnectionUiState,
Expand Down Expand Up @@ -292,6 +296,8 @@ describe("WsTransport", () => {
});

it("marks unary requests as slow until the first server ack arrives", async () => {
const slowAckThresholdMs = 25;
setSlowRpcAckThresholdMsForTests(slowAckThresholdMs);
const transport = new WsTransport("ws://localhost:3020");

const requestPromise = transport.request((client) =>
Expand Down Expand Up @@ -320,7 +326,7 @@ describe("WsTransport", () => {
tag: WS_METHODS.serverUpsertKeybinding,
},
]);
}, 5_000);
}, 1_000);

socket.serverMessage(
JSON.stringify({
Expand All @@ -343,7 +349,7 @@ describe("WsTransport", () => {
expect(getSlowRpcAckRequests()).toEqual([]);

await transport.dispose();
}, 10_000);
}, 5_000);

it("sends unary RPC requests and resolves successful exits", async () => {
const transport = new WsTransport("ws://localhost:3020");
Expand Down
Loading