New issue
Advanced search Search tips

Issue 625934 link

Starred by 3 users

Issue metadata

Status: Duplicate
Merged: issue 375297
Owner:
Closed: Sep 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: ----
Type: Bug

Blocked on:
issue 375297


Previous locations:
v8:5152


Sign in to add a comment

Why the loop is not finished?

Reported by g.auersb...@gmail.com, Jun 25 2016

Issue description

We need to calculate the CRC32 value of files to upload to ensure file integrity. We use the standard FileReader which provides an onload method which fires when the data is in memory. In the event handler we calculate the CRC value, then we read the next file and do the same.

In the following test we create a random file, read the file data and create the CRC. But, the engine does not wait until the whole process finished, instead it returns after the random file data has been created.

Like other browsers, we've expected that Chromiom based browsers finish all loops. Online demo: http://www.backload.org/lab/crc32/run.html


Code:

// Lookup table for the polynomial 3988292384 (0xEDB88320)
var crc32Lookup = new Int32Array(256);
(function () {
    var i, j, n;

    for (var i = 0; i < 256; i++) {
        n = i;
        for (var j = 8; j > 0; j--) {
            if ((n & 1) == 1) {
                n = (n >>> 1) ^ 3988292384
            } else {
                n = n >>> 1
            }
        }
        crc32Lookup[i] = n

    }
})();


// Calculate CRC32
function crc32(data) {
    var crc = 0xFFFFFFFF

    for (var i = 0; i < data.length; i++)
        crc = (crc >>> 8) ^ crc32Lookup[data[i] ^ (crc & 0x000000FF)];

    crc = crc = ~crc;
    return crc < 0 ? (0xFFFFFFFF + crc + 1) : crc;
}

// Main test method
function runTest(result) {
    var len = 50000000, // 50MB
        data = new Uint8Array(len),
        data2,
        blob,
        crc;



    // Fill array with random values from 0-255 
    result.timeStart = performance.now();
    for (var i = 0; i < len; i++) {
        data[i] = Math.floor(Math.random() * 256);
    }
    result.timeCreate = performance.now() - result.timeStart;

    // Simulate file data (blob)
    blob = new Blob([data], { type: 'application/octet-binary' });


    // Using a FileReader to read the blob into an ArrayBuffer
    var reader = new FileReader();
    reader.onload = function (e) {
        var data = new Uint8Array(e.target.result, 0, e.target.result.byteLength);

        // Calculate CRC
        result.timeCrc = performance.now();
        result.crc = crc32(data);
        var end = performance.now()


        // Calculate compute time for the current and all iterations
        result.timeCrc = end - result.timeCrc;
        result.timeTotal = end - result.timeStart;
        result.totalCreate += result.timeCreate;
        result.totalCrc += result.timeCrc;
        result.totalTime += result.timeTotal;

        // Print result and next iteration
        result.iter += 1;
        result.printResult();

		reader = null;
        data = null;
        r = null;
        if (result.iter < result.totalIter)
            runTest(result);
    };
    reader.readAsArrayBuffer(blob);
}
 

Comment 1 Deleted

The loop stops because of FileReader errors. I've added an onerror event handler: 
reader.onerror= function (e) {
}

See online: http://www.backload.org/lab/crc32/run.html
This only happens in v8. All other browsers finish the calculation correctly.
What Chrome version are you using?
Cc: jochen@chromium.org yangguo@chromium.org
Components: API
Status: Available (was: Untriaged)
can repro with  51.0.2704.103 and 100 iterations.
Project: chromium
Moved issue v8:5152 to now be  issue chromium:625934 .
Components: Blink>FileAPI
Owner: tyoshino@chromium.org
Status: Assigned (was: Available)
smaller repro:

<script>
  // Main test method
  function runTest(iteration) {
    console.log("iteration " + iteration);
    var data = new Uint8Array(50000000);
    blob = new Blob([data], {
      type: 'application/octet-binary'
    });
    var reader = new FileReader();
    reader.onerror = function(e) {
      console.log(JSON.stringify(e));
    }
    reader.onload = function(e) {
      if (iteration < 100) runTest(iteration + 1);
    };
    reader.readAsArrayBuffer(blob);
  }
  runTest(0);
</script>
Blockedon: 375297
Owner: dmu...@chromium.org
With the repro in #6, the reader's error is:

NotFoundError A requested file or directory could not be found at the time an operation was processed.

Given that I hit this at the 500MB mark, this looks like it could be a dupe of  issue 375297 

dmurph@ - can you take a look?

Comment 9 by dmu...@chromium.org, Sep 16 2016

Mergedinto: 375297
Status: Duplicate (was: Assigned)
Yeah definitely hitting that limit.
Components: Blink>Storage>FileAPI
Components: -Blink>FileAPI

Sign in to add a comment