Repository navigation
Commit 8f83e6f
fix(everything): address review feedback on shutdown and subscription typing
From Copilot's review of #4551.
transports/streamableHttp.ts — `httpServer.close()` is callback-based, and
`process.exit(0)` ran immediately after it, so the process could exit with
the listen socket still open and pending writes unflushed. Now awaited.
`closeAllConnections()` is called first because `close()` waits for existing
connections to end; that call is defensive rather than demonstrated -- a
contrast test with an idle keep-alive connection closed in ~2ms either way,
so it guards the documented behavior, not a reproduced hang. Verified the
sequence resolves and the port is genuinely rebindable afterwards, i.e. the
close completes rather than merely being initiated.
resources/subscriptions.ts — `ctx.sessionId` was cast `as string` in both
handlers directly beneath a comment saying it can be undefined, and the
subscriber sets were then narrowed to `Set<string>` while the map is declared
`Map<string, Set<string | undefined>>`. The runtime behavior was already
correct: on stdio there is no session, `undefined` is a legitimate subscriber
key identifying the single sessionless connection, and the update path
matches on it. Only the types disagreed. Casts removed and the intent stated
in a comment; the lookups collapse to `??` and `?.` in the process.
Also made `sendSimulatedResourceUpdates` synchronous -- it was declared
`async`/`Promise<void>` while awaiting nothing, since publishing through the
notifier is fire-and-forget, and the JSDoc claimed it resolved once
notifications were sent. Both call sites already discarded the return value.
While there, dropped a dead `else` branch in the same loop that called
`subscribers.delete(sessionId)` on the branch where `subscribers.has(
sessionId)` was already false -- a guaranteed no-op, commented "subscriber
has disconnected". It cannot reap anyone; that is `cleanupSession` ->
`stopSimulatedResourceUpdates`. Pre-existing on main and not introduced
here, removed because the surrounding lines were already being rewritten.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent 6d8c190 commit 8f83e6f
2 files changed
Lines changed: 30 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| |||
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
56 | | - | |
57 | | - | |
58 | | - | |
| 58 | + | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
73 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
74 | 77 | | |
75 | 78 | | |
76 | 79 | | |
| |||
84 | 87 | | |
85 | 88 | | |
86 | 89 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
110 | 113 | | |
111 | 114 | | |
112 | | - | |
113 | 115 | | |
114 | | - | |
| 116 | + | |
115 | 117 | | |
116 | 118 | | |
117 | | - | |
| 119 | + | |
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
125 | 129 | | |
126 | 130 | | |
127 | | - | |
128 | | - | |
129 | 131 | | |
130 | 132 | | |
131 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
89 | 96 | | |
90 | 97 | | |
91 | 98 | | |
| |||
0 commit comments