Skip to content

Commit 85e5498

Browse files
committed
up2k.js: set timeouts for uploads
in the event that an upload chunk gets stuck, the js would never stop waiting for a response, requiring a page reload improves reliability when running behind a reverse-proxy which is configured to never timeout requests (can make sense when combined with other services on the same box)
1 parent a19a0fa commit 85e5498

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

copyparty/web/up2k.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,7 +2186,7 @@ function up2k_init(subtle) {
21862186
st.busy.head.push(t);
21872187

21882188
var xhr = new XMLHttpRequest();
2189-
xhr.onerror = function () {
2189+
xhr.onerror = xhr.ontimeout = function () {
21902190
console.log('head onerror, retrying', t.name, t);
21912191
if (!toast.visible)
21922192
toast.warn(9.98, L.u_enethd + "\n\nfile: " + t.name, t);
@@ -2230,6 +2230,7 @@ function up2k_init(subtle) {
22302230
try { orz(e); } catch (ex) { vis_exh(ex + '', 'up2k.js', '', '', ex); }
22312231
};
22322232

2233+
xhr.timeout = 34000;
22332234
xhr.open('HEAD', t.purl + uricom_enc(t.name), true);
22342235
xhr.send();
22352236
}
@@ -2255,7 +2256,7 @@ function up2k_init(subtle) {
22552256
console.log("sending keepalive handshake", t.name, t);
22562257

22572258
var xhr = new XMLHttpRequest();
2258-
xhr.onerror = function () {
2259+
xhr.onerror = xhr.ontimeout = function () {
22592260
if (t.t_busied != me) // t.done ok
22602261
return console.log('zombie handshake onerror', t.name, t);
22612262

@@ -2512,6 +2513,7 @@ function up2k_init(subtle) {
25122513

25132514
xhr.open('POST', t.purl, true);
25142515
xhr.responseType = 'text';
2516+
xhr.timeout = 42000;
25152517
xhr.send(JSON.stringify(req));
25162518
}
25172519

@@ -2631,15 +2633,21 @@ function up2k_init(subtle) {
26312633
btot = Math.floor(st.bytes.total / 1024 / 1024);
26322634

26332635
xhr.upload.onprogress = function (xev) {
2634-
var nb = xev.loaded;
2635-
st.bytes.inflight += nb - xhr.bsent;
2636+
var nb = xev.loaded,
2637+
db = nb - xhr.bsent;
2638+
2639+
if (!db)
2640+
return;
2641+
2642+
st.bytes.inflight += db;
26362643
xhr.bsent = nb;
2644+
xhr.timeout = 64000 + Date.now() - xhr.t0;
26372645
pvis.prog(t, pcar, nb);
26382646
};
26392647
xhr.onload = function (xev) {
26402648
try { orz(xhr); } catch (ex) { vis_exh(ex + '', 'up2k.js', '', '', ex); }
26412649
};
2642-
xhr.onerror = function (xev) {
2650+
xhr.onerror = xhr.ontimeout = function (xev) {
26432651
if (crashed)
26442652
return;
26452653

@@ -2666,6 +2674,8 @@ function up2k_init(subtle) {
26662674
xhr.overrideMimeType('Content-Type', 'application/octet-stream');
26672675

26682676
xhr.bsent = 0;
2677+
xhr.t0 = Date.now();
2678+
xhr.timeout = 42000;
26692679
xhr.responseType = 'text';
26702680
xhr.send(t.fobj.slice(car, cdr));
26712681
}

0 commit comments

Comments
 (0)