Merge pull request #2039 from modelcontextprotocol/v2/chore/1959-no-floating-promises
chore(lint): enable @typescript-eslint/no-floating-promises in all five ESLint scopes
This commit is contained in:
commit
405d0f4d0d
1 changed files with 656 additions and 113 deletions
|
|
@ -99,6 +99,22 @@ import { ZodError } from "zod";
|
|||
*/
|
||||
const SSE_PRIMING_COMMENT = ":\n\n";
|
||||
|
||||
/**
|
||||
* Close an SSE stream from inside an `onAbort` listener, discarding the
|
||||
* rejection.
|
||||
*
|
||||
* `close()` is async and the peer is, by definition, already gone here — a
|
||||
* write that loses the race rejects with nothing left to recover. The listener
|
||||
* itself cannot own the promise either: Hono's `abort()` invokes subscribers
|
||||
* with a bare `subscriber()` (`hono/utils/stream`), so a promise *returned*
|
||||
* from the listener is floated by Hono rather than awaited, turning an
|
||||
* `async` listener into the same unhandled rejection one layer up. Swallowing
|
||||
* it here is the only place the rejection has an owner.
|
||||
*/
|
||||
export function closeAbortedStream(stream: { close(): Promise<void> }): void {
|
||||
stream.close().catch(() => {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Shape of the initial config returned by GET /api/config (defaults for client).
|
||||
*/
|
||||
|
|
@ -854,7 +870,7 @@ export function createRemoteApp(
|
|||
stream.onAbort(() => {
|
||||
// Client disconnected - clear event consumer
|
||||
const shouldCleanup = session.clearEventConsumer();
|
||||
stream.close();
|
||||
closeAbortedStream(stream);
|
||||
|
||||
// If transport is dead and no client connected, cleanup session
|
||||
if (shouldCleanup || session.isTransportDead()) {
|
||||
|
|
@ -2460,7 +2476,7 @@ export function createRemoteApp(
|
|||
stream.onAbort(() => {
|
||||
serverEventSubscribers.delete(send);
|
||||
void maybeStopWatcher();
|
||||
stream.close();
|
||||
closeAbortedStream(stream);
|
||||
});
|
||||
|
||||
// Hono closes the stream the moment this callback returns, so hold the
|
||||
|
|
|
|||
Loading…
Reference in a new issue