Skip to content

Commit d4ab61c

Browse files
fix(client): avoid memory leak with abort signals
1 parent 8513ce5 commit d4ab61c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,10 @@ export class Morphik {
575575
controller: AbortController,
576576
): Promise<Response> {
577577
const { signal, method, ...options } = init || {};
578-
if (signal) signal.addEventListener('abort', () => controller.abort());
578+
const abort = controller.abort.bind(controller);
579+
if (signal) signal.addEventListener('abort', abort, { once: true });
579580

580-
const timeout = setTimeout(() => controller.abort(), ms);
581+
const timeout = setTimeout(abort, ms);
581582

582583
const isReadableBody =
583584
((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||

0 commit comments

Comments
 (0)