-
Notifications
You must be signed in to change notification settings - Fork 328
feat: Add stall detection to recover from frozen uploads #775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
m7kvqbe1
wants to merge
11
commits into
tus:main
Choose a base branch
from
m7kvqbe1:feat/stall-detection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
875c31d
Add stall detection to recover from frozen uploads
m7kvqbe1 6eb57be
Fix exports for HttpStack modules
m7kvqbe1 2752c13
Add value-based stall detection to catch stuck progress
m7kvqbe1 8562315
fixup! Add value-based stall detection to catch stuck progress
m7kvqbe1 e5032c0
fixup! Add value-based stall detection to catch stuck progress
m7kvqbe1 fb2e339
fixup! Add value-based stall detection to catch stuck progress
m7kvqbe1 daf2ae0
fixup! Add value-based stall detection to catch stuck progress
m7kvqbe1 13bef21
fixup! Add value-based stall detection to catch stuck progress
m7kvqbe1 4e30ea5
Fix issue with stall detection errors bubbling to consumer
m7kvqbe1 bf59675
Fix linting issues
Acconut de184c8
Get rid of unnecessary inner function
Acconut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { log } from './logger.js' | ||
import type { StallDetectionOptions } from './options.js' | ||
|
||
export class StallDetector { | ||
private options: StallDetectionOptions | ||
private onStallDetected: (reason: string) => void | ||
|
||
private intervalId: ReturnType<typeof setInterval> | null = null | ||
private lastProgressTime = 0 | ||
private lastProgressValue = 0 | ||
private isActive = false | ||
|
||
constructor(options: StallDetectionOptions, onStallDetected: (reason: string) => void) { | ||
this.options = options | ||
this.onStallDetected = onStallDetected | ||
} | ||
|
||
/** | ||
* Start monitoring for stalls | ||
*/ | ||
start() { | ||
if (this.intervalId) { | ||
return // Already started | ||
} | ||
|
||
this.lastProgressTime = Date.now() | ||
this.lastProgressValue = 0 | ||
this.isActive = true | ||
|
||
log( | ||
`tus: starting stall detection with checkInterval: ${this.options.checkInterval}ms, stallTimeout: ${this.options.stallTimeout}ms`, | ||
) | ||
|
||
// Setup periodic check | ||
this.intervalId = setInterval(() => { | ||
if (!this.isActive) { | ||
return | ||
} | ||
|
||
const now = Date.now() | ||
if (this._isProgressStalled(now)) { | ||
this._handleStall('no progress') | ||
} | ||
}, this.options.checkInterval) | ||
} | ||
|
||
/** | ||
* Stop monitoring for stalls | ||
*/ | ||
stop(): void { | ||
this.isActive = false | ||
if (this.intervalId) { | ||
clearInterval(this.intervalId) | ||
this.intervalId = null | ||
} | ||
} | ||
|
||
/** | ||
* Update progress information | ||
* @param progressValue The current progress value (bytes uploaded) | ||
*/ | ||
updateProgress(progressValue: number): void { | ||
// Only update progress time if the value has actually changed | ||
if (progressValue !== this.lastProgressValue) { | ||
this.lastProgressTime = Date.now() | ||
this.lastProgressValue = progressValue | ||
} | ||
} | ||
|
||
/** | ||
* Check if upload has stalled based on progress events | ||
*/ | ||
private _isProgressStalled(now: number): boolean { | ||
const timeSinceProgress = now - this.lastProgressTime | ||
const stallTimeout = this.options.stallTimeout | ||
const isStalled = timeSinceProgress > stallTimeout | ||
|
||
if (isStalled) { | ||
log(`tus: no progress for ${timeSinceProgress}ms (limit: ${stallTimeout}ms)`) | ||
} | ||
|
||
return isStalled | ||
} | ||
|
||
/** | ||
* Handle a detected stall | ||
*/ | ||
private _handleStall(reason: string): void { | ||
log(`tus: upload stalled: ${reason}`) | ||
this.stop() | ||
this.onStallDetected(reason) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.