InvalidStateError raised when cancel a ReadableStream from Fetch API

Issue #11265202 • Assigned to Steven K.


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

Sign in to watch or report this issue.

Steps to reproduce


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

Reproduce code:
The whole implementation is in…
Simplified code:

var requestAbort = false;

function abortVideo() {
    requestAbort = true;

function pump(reader, context) {
    return (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 = '';

    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.


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