Repository navigation
Commit 66d55db
committed
fix(server): add re-entrancy guard to close() to prevent stack overflow
When close() is called while cleanup() callbacks are still running (e.g. a
cleanup function that triggers onclose which calls close() again), the
transport enters infinite recursion causing RangeError: Maximum call stack size
exceeded — especially acute when multiple transports close simultaneously.
The fix adds a _closed boolean flag checked at the top of close(). If the
transport is already closing, subsequent calls return immediately instead
of recursing. This is safe because close() is idempotent.
Also applies to the idempotent close() contract: calling close() multiple
times should have no additional effect after the first call.
Fixes modelcontextprotocol#1699.1 parent 984a27e commit 66d55db
1 file changed
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
| |||
900 | 901 | | |
901 | 902 | | |
902 | 903 | | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
903 | 907 | | |
904 | 908 | | |
905 | 909 | | |
| |||
0 commit comments