Skip to content

Commit c8e998e

Browse files
cliffhallclaude
andcommitted
fix(everything): retry an idle session whose close failed
When closing an idle session's transport rejected, the session stayed in the transport map but was no longer watched, so no later look tried it again and it was kept until a DELETE or shutdown: the retention this change removes. The session is now watched again after a failed close, so it is tried again after another idle timeout. The test for the failure now also checks that the session is still served, and is evicted at the next timeout. Part of #5558 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
1 parent 780f0c9 commit c8e998e

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎src/everything/__tests__/streamable-http.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ describe("idle sessions (#5558)", () => {
722722
await response.text();
723723
});
724724

725-
it("logs an idle session that fails to close", async () => {
725+
it("logs an idle session that fails to close, and evicts it at a later look", async () => {
726726
await serveWithIdleTimeout(IDLE);
727727
const { sessionId } = await rawInitialize();
728728
const failure = new Error("close failed");
@@ -737,6 +737,19 @@ describe("idle sessions (#5558)", () => {
737737
failure,
738738
),
739739
);
740+
// The failed close left the session in place, and still served.
741+
const held = await post(ping, sessionId);
742+
expect(held.status).toBe(200);
743+
await held.text();
744+
745+
// It is watched again, so the next timeout closes it for real.
746+
await vi.waitFor(() => {
747+
vi.advanceTimersByTime(IDLE);
748+
expect(log).toHaveBeenCalledWith(
749+
`Transport closed for session ${sessionId}, removing from transports map`,
750+
);
751+
});
752+
expect((await post(ping, sessionId)).status).toBe(404);
740753
});
741754

742755
it("stops looking for idle sessions on shutdown", async () => {

‎src/everything/transports/streamableHttp.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,13 @@ export function createApp(
223223
transports
224224
.get(sessionId)
225225
?.close()
226-
.catch((error: unknown) =>
227-
console.log(`Error closing idle session ${sessionId}:`, error),
228-
);
226+
.catch((error: unknown) => {
227+
console.log(`Error closing idle session ${sessionId}:`, error);
228+
// The session is still held, so watch it again: it is tried again
229+
// after another timeout rather than kept for good. (If it did end,
230+
// that later look finds no transport and just forgets it.)
231+
idle.add(sessionId);
232+
});
229233
});
230234

231235
// A session-less POST's body is parsed once, to classify it and serve it.

0 commit comments

Comments
 (0)