Skip to content

Commit e5032c0

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

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

lib/StallDetector.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
import { log } from './logger.js'
22
import type { StallDetectionOptions } from './options.js'
3-
import type { HttpStack } from './options.js'
43

54
export class StallDetector {
65
private options: StallDetectionOptions
7-
private httpStack: HttpStack
86
private onStallDetected: (reason: string) => void
97

108
private intervalId: ReturnType<typeof setInterval> | null = null
119
private lastProgressTime = 0
1210
private lastProgressValue = 0
1311
private isActive = false
1412

15-
constructor(
16-
options: StallDetectionOptions,
17-
httpStack: HttpStack,
18-
onStallDetected: (reason: string) => void,
19-
) {
13+
constructor(options: StallDetectionOptions, onStallDetected: (reason: string) => void) {
2014
this.options = options
21-
this.httpStack = httpStack
2215
this.onStallDetected = onStallDetected
2316
}
2417

lib/upload.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -850,17 +850,13 @@ export class BaseUpload {
850850
if (this.options.stallDetection?.enabled) {
851851
// Only enable stall detection if the HTTP stack supports progress events
852852
if (this.options.httpStack.supportsProgressEvents()) {
853-
stallDetector = new StallDetector(
854-
this.options.stallDetection,
855-
this.options.httpStack,
856-
(reason: string) => {
857-
// Handle stall by aborting the current request and triggering retry
858-
if (this._req) {
859-
this._req.abort()
860-
}
861-
this._retryOrEmitError(new Error(`Upload stalled: ${reason}`))
862-
},
863-
)
853+
stallDetector = new StallDetector(this.options.stallDetection, (reason: string) => {
854+
// Handle stall by aborting the current request and triggering retry
855+
if (this._req) {
856+
this._req.abort()
857+
}
858+
this._retryOrEmitError(new Error(`Upload stalled: ${reason}`))
859+
})
864860
// Don't start yet - will be started after onBeforeRequest
865861
} else {
866862
log(

0 commit comments

Comments
 (0)