Skip to content

Commit

Permalink
Fix - handle reordering of fragments in multipart reply #319
Browse files Browse the repository at this point in the history
In case when reordering detected - try to search in all requested
fragments for provided data range.
Will not work if server creates more fragments than requested.
Coalesing should be OK.

Special situation of EOS server
  • Loading branch information
linev committed Oct 30, 2024
1 parent 5b4f945 commit 17265d0
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions modules/io.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2896,7 +2896,7 @@ class TFile {
// multipart messages requires special handling

const indx = hdr.indexOf('boundary=');
let boundary = '', n = first, o = 0;
let boundary = '', n = first, o = 0, normal_order = true;
if (indx > 0) {
boundary = hdr.slice(indx + 9);
if ((boundary[0] === '"') && (boundary[boundary.length - 1] === '"'))
Expand Down Expand Up @@ -2950,12 +2950,34 @@ class TFile {
blobs.push(new DataView(res, o, place[n + 1]));
o += place[n + 1];
n += 2;
} else {
} else if (normal_order) {
const n0 = n;
while ((n < last) && (place[n] >= segm_start) && (place[n] + place[n + 1] - 1 <= segm_last)) {
blobs.push(new DataView(res, o + place[n] - segm_start, place[n + 1]));
n += 2;
}

if (n > n0)
o += (segm_last - segm_start + 1);
else
normal_order = false;
}

if (!normal_order) {
// special situation when server reorder segments in the reply
let isany = false;
for (let n1 = n; n1 < last; n1 += 2) {
if ((place[n1] >= segm_start) && (place[n1] + place[n1 + 1] - 1 <= segm_last)) {
blobs[n1/2] = new DataView(res, o + place[n1] - segm_start, place[n1 + 1]);
isany = true;
}
}
if (!isany)
return rejectFunc(Error(`Provided fragment ${segm_start} - ${segm_last} out of requested multi-range request`));

while (blobs[n/2])
n += 2;

o += (segm_last - segm_start + 1);
}
}
Expand Down

0 comments on commit 17265d0

Please sign in to comment.