InvalidStateError raised when cancel a ReadableStream from Fetch API

Issue #11265202 • Assigned to Steven K.

Details

Author
Antón M.
Created
Mar 14, 2017
Privacy
This issue is public.
Found in
  • Microsoft Edge
Found in build #
15.15048
Reports
Reported by 2 people

Sign in to watch or report this issue.

Steps to reproduce

Affect:
15.15048

Description:
Like issue #8196907, use fetch API to visit a large binary file (such as video file), and read binary data via ReadableStream in order to do stream IO.
During the halfway of download progress, call ReadableStreamReader.cancel() to abort a stream reading process before complete. It will raise an InvalidStateError in the Promise of ReadableStreamReader.read().

Reproduce code:
The whole implementation is in github.com/Bilibili/flv.j…
Simplified code:

var requestAbort = false;

function abortVideo() {
    requestAbort = true;
}

function pump(reader, context) {
    return reader.read().then(function (result) {
        if (result.done) {
            console.log('ReadableStreamReader: complete! Received ' + context.receivedLength);
        } else {
            if (requestAbort === true) {
                requestAbort = false;
                return reader.cancel();
            }

            var chunk = result.value;
            console.log('ReadableStreamReader: Partial chunk, chunkSize = ' + chunk.byteLength);

            context.receivedLength += chunk.byteLength;
            return pump(reader, context);
        }
    }).catch(function (e) {
        // Here is the InvalidStateError
        throw e;
    });
}

function fetchVideo() {
    var url = 'http://127.0.0.1/video/railgun.mkv';

    var headers = new Headers();
    var param = {
        method: 'GET',
        headers: headers,
        mode: 'cors',
        cache: 'default'
    };

    var context = {
        receivedLength: 0
    };

    fetch(url, param).then(function (res) {
        console.log('Content-Length: ' + res.headers.get('Content-Length'));
        return pump(res.body.getReader(), context);
    }).catch(function (e) {
        throw e;
    });
}

Expected result:
The download progress should be aborted without any exception raised.
In Chrome, ReadableStreamReader.cancel() works well since Chrome 43.

Attachments

0 attachments

    Comments and activity

    • Changed Steps to Reproduce

    • User magicxqq can provide more information if needed. He is the original reporter in this tweet.

    • Thank you @Antón M.
      I am the reporter of this issue

    • Microsoft Edge Team

      Changed Assigned To to “Steven K.”

    You need to sign in to your Microsoft account to add a comment.

    Sign in