Skip to content

fix(app): merge abort signals in apiFetch#2

Merged
GeminiLight merged 1 commit intoGeminiLight:mainfrom
ppsmk388:fix/api-fetch-signal-merge
Mar 22, 2026
Merged

fix(app): merge abort signals in apiFetch#2
GeminiLight merged 1 commit intoGeminiLight:mainfrom
ppsmk388:fix/api-fetch-signal-merge

Conversation

@ppsmk388
Copy link
Contributor

Ensure apiFetch honors both timeout cancellation and caller-provided AbortSignal.\n\nPreviously, providing an external signal could bypass the internal timeout signal.\nThis patch bridges the external signal into a shared AbortController so either source can abort the request.\n\nAlso cleans up the external abort event listener in finally to avoid leaks.

Ensure apiFetch honors both timeout cancellation and caller-provided AbortSignal.\n\nPreviously, providing an external signal could bypass the internal timeout signal.\nThis patch bridges the external signal into a shared AbortController so either source can abort the request.\n\nAlso cleans up the external abort event listener in finally to avoid leaks.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the shared apiFetch helper to correctly support both request timeouts and caller-provided cancellation signals, ensuring the timeout isn’t accidentally disabled when an external AbortSignal is supplied.

Changes:

  • Creates an internal AbortController when a timeout and/or external signal is present.
  • Bridges a caller-provided AbortSignal into the internal controller so external aborts cancel the underlying fetch.
  • Ensures timers and abort listeners are cleaned up in finally.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

let removeExternalAbortListener: (() => void) | undefined;

if (timeout > 0) {
if (timeout > 0 || externalSignal) {
Comment on lines +42 to +45
if (externalSignal.aborted) {
controller.abort();
} else {
const onAbort = () => controller?.abort();
Comment on lines 25 to 33
export async function apiFetch<T>(url: string, opts: ApiFetchOptions = {}): Promise<T> {
const { timeout = 30_000, signal: externalSignal, ...fetchOpts } = opts;

let controller: AbortController | undefined;
let timeoutId: ReturnType<typeof setTimeout> | undefined;
let removeExternalAbortListener: (() => void) | undefined;

if (timeout > 0) {
if (timeout > 0 || externalSignal) {
controller = new AbortController();
@GeminiLight GeminiLight merged commit 460014f into GeminiLight:main Mar 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants