Skip to content

Commit fb2e339

Browse files
committed
fixup! Add value-based stall detection to catch stuck progress
1 parent e5032c0 commit fb2e339

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

lib/upload.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,25 +1099,27 @@ async function sendRequest(
10991099
await options.onBeforeRequest(req)
11001100
}
11011101

1102-
// Start stall detection after onBeforeRequest completes but before the actual network request
1103-
if (stallDetector) {
1104-
stallDetector.start()
1105-
}
1106-
1107-
try {
1108-
const res = await req.send(body)
1109-
1110-
if (typeof options.onAfterResponse === 'function') {
1111-
await options.onAfterResponse(req, res)
1102+
const sendWithStallDetection = async (): Promise<HttpResponse> => {
1103+
if (stallDetector) {
1104+
stallDetector.start()
11121105
}
11131106

1114-
return res
1115-
} finally {
1116-
// Always stop the stall detector when the request completes (success or failure)
1117-
if (stallDetector) {
1118-
stallDetector.stop()
1107+
try {
1108+
return await req.send(body)
1109+
} finally {
1110+
if (stallDetector) {
1111+
stallDetector.stop()
1112+
}
11191113
}
11201114
}
1115+
1116+
const res = await sendWithStallDetection()
1117+
1118+
if (typeof options.onAfterResponse === 'function') {
1119+
await options.onAfterResponse(req, res)
1120+
}
1121+
1122+
return res
11211123
}
11221124

11231125
/**

0 commit comments

Comments
 (0)