Skip to content

Commit 194c886

Browse files
committed
fix: clear abort timeout after response was received
1 parent 27996d3 commit 194c886

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/fetch.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch {
149149
}
150150
}
151151

152+
let abortTimeout: number | undefined;
153+
152154
// TODO: Can we merge signals?
153155
if (!context.options.signal && context.options.timeout) {
154156
const controller = new AbortController();
155-
setTimeout(() => controller.abort(), context.options.timeout);
157+
abortTimeout = setTimeout(() => controller.abort(), context.options.timeout);
156158
context.options.signal = controller.signal;
157159
}
158160

@@ -161,7 +163,9 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch {
161163
context.request,
162164
context.options as RequestInit
163165
);
166+
clearTimeout(abortTimeout);
164167
} catch (error) {
168+
clearTimeout(abortTimeout);
165169
context.error = error as Error;
166170
if (context.options.onRequestError) {
167171
await context.options.onRequestError(context as any);

0 commit comments

Comments
 (0)