@@ -9,6 +9,8 @@ export class StallDetector {
99
1010 private intervalId : ReturnType < typeof setInterval > | null = null
1111 private lastProgressTime = 0
12+ private lastProgressValue = 0
13+ private progressValueCount = 0
1214 private isActive = false
1315
1416 constructor (
@@ -30,6 +32,8 @@ export class StallDetector {
3032 }
3133
3234 this . lastProgressTime = Date . now ( )
35+ this . lastProgressValue = 0
36+ this . progressValueCount = 0
3337 this . isActive = true
3438
3539 log (
@@ -43,7 +47,9 @@ export class StallDetector {
4347 }
4448
4549 const now = Date . now ( )
46- if ( this . _isProgressStalled ( now ) ) {
50+ if ( this . _isProgressValueStalled ( ) ) {
51+ this . _handleStall ( 'progress value not changing' )
52+ } else if ( this . _isProgressStalled ( now ) ) {
4753 this . _handleStall ( 'no progress events received' )
4854 }
4955 } , this . options . checkInterval )
@@ -62,9 +68,18 @@ export class StallDetector {
6268
6369 /**
6470 * Update progress information
71+ * @param progressValue The current progress value (bytes uploaded)
6572 */
66- updateProgress ( ) : void {
73+ updateProgress ( progressValue : number ) : void {
6774 this . lastProgressTime = Date . now ( )
75+
76+ // Track if the progress value has changed
77+ if ( progressValue === this . lastProgressValue ) {
78+ this . progressValueCount ++
79+ } else {
80+ this . lastProgressValue = progressValue
81+ this . progressValueCount = 0
82+ }
6883 }
6984
7085 /**
@@ -82,6 +97,25 @@ export class StallDetector {
8297 return isStalled
8398 }
8499
100+ /**
101+ * Check if upload has stalled based on progress value not changing
102+ */
103+ private _isProgressValueStalled ( ) : boolean {
104+ // Calculate how many times we expect progress to have changed based on check intervals
105+ const expectedProgressChanges = Math . floor (
106+ this . options . stallTimeout / this . options . checkInterval ,
107+ )
108+ const isStalled = this . progressValueCount >= expectedProgressChanges
109+
110+ if ( isStalled ) {
111+ log (
112+ `tus: progress value stuck at ${ this . lastProgressValue } bytes for ${ this . progressValueCount } checks` ,
113+ )
114+ }
115+
116+ return isStalled
117+ }
118+
85119 /**
86120 * Handle a detected stall
87121 */
0 commit comments