Skip to content

Commit a512684

Browse files
address review: ensure cleanup runs even if user onclose throws
Wrap the user-provided onclose callback in try/finally so response handler rejection and abort controller firing happen even if the callback throws. Consistent with the pattern in InMemoryTransport.
1 parent c277b48 commit a512684

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

packages/core/src/shared/protocol.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -742,14 +742,17 @@ export abstract class Protocol<ContextT extends BaseContext> {
742742
const error = new SdkError(SdkErrorCode.ConnectionClosed, 'Connection closed');
743743

744744
this._transport = undefined;
745-
this.onclose?.();
746745

747-
for (const handler of responseHandlers.values()) {
748-
handler(error);
749-
}
746+
try {
747+
this.onclose?.();
748+
} finally {
749+
for (const handler of responseHandlers.values()) {
750+
handler(error);
751+
}
750752

751-
for (const controller of requestHandlerAbortControllers.values()) {
752-
controller.abort(error);
753+
for (const controller of requestHandlerAbortControllers.values()) {
754+
controller.abort(error);
755+
}
753756
}
754757
}
755758

0 commit comments

Comments
 (0)