added download hang detection and error reporting

This commit is contained in:
Danny Coates 2019-08-08 13:54:02 -07:00
parent c925fae696
commit 7073cc8ce6
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
1 changed files with 19 additions and 0 deletions

View File

@ -112,6 +112,7 @@ export default class FileReceiver extends Nanobus {
} }
async downloadStream(noSave = false) { async downloadStream(noSave = false) {
const start = Date.now();
const onprogress = p => { const onprogress = p => {
this.progress = [p, this.fileInfo.size]; this.progress = [p, this.fileInfo.size];
this.emit('progress'); this.emit('progress');
@ -162,11 +163,29 @@ export default class FileReceiver extends Nanobus {
} }
let prog = 0; let prog = 0;
let hangs = 0;
while (prog < this.fileInfo.size) { while (prog < this.fileInfo.size) {
const msg = await this.sendMessageToSw({ const msg = await this.sendMessageToSw({
request: 'progress', request: 'progress',
id: this.fileInfo.id id: this.fileInfo.id
}); });
if (msg.progress === prog) {
hangs++;
} else {
hangs = 0;
}
if (hangs > 30) {
// TODO: On Chrome we don't get a cancel
// signal so one is indistinguishable from
// a hang. We may be able to detect
// which end is hung in the service worker
// to improve on this.
const e = new Error('hung download');
e.duration = Date.now() - start;
e.size = this.fileInfo.size;
e.progress = prog;
throw e;
}
prog = msg.progress; prog = msg.progress;
onprogress(prog); onprogress(prog);
await delay(1000); await delay(1000);