Skip to content

Commit

Permalink
Fix HttpClient event handler leak (#4107)
Browse files Browse the repository at this point in the history
Fix leak in signalGlobal event listeners
  • Loading branch information
dapplion authored and g11tech committed Jun 3, 2022
1 parent 82d23e0 commit 9bb9127
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/api/src/client/utils/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ export class HttpClient implements IHttpClient {
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);

// Attach global signal to this request's controller
const signalGlobal = this.getAbortSignal && this.getAbortSignal();
const onGlobalSignalAbort = controller.abort.bind(controller);
const signalGlobal = this.getAbortSignal?.();
if (signalGlobal) {
signalGlobal.addEventListener("abort", () => controller.abort());
signalGlobal.addEventListener("abort", onGlobalSignalAbort);
}

const routeId = opts.routeId; // TODO: Should default to "unknown"?
Expand Down Expand Up @@ -130,7 +131,7 @@ export class HttpClient implements IHttpClient {

clearTimeout(timeout);
if (signalGlobal) {
signalGlobal.removeEventListener("abort", controller.abort);
signalGlobal.removeEventListener("abort", onGlobalSignalAbort);
}
}
}
Expand Down

0 comments on commit 9bb9127

Please sign in to comment.