Skip to content

Unexpected ERR_INVALID_STATE error #1137

Closed

Description

@szmarczak
import {fetch} from 'undici';

const start = Date.now();
const controller = new AbortController();
const response = await fetch('https://speed.hetzner.de/100MB.bin', {signal: controller.signal});
console.log(Date.now() - start, response.bodyUsed);
(async () => {
    try {
        await response.text();
        console.log(Date.now() - start, 'read');
    } catch (error) {
        console.error(Date.now() - start, error.name);
    }
})();
console.log(Date.now() - start, 'aborting');
controller.abort();
szm@pop-os:~/Desktop/demo$ node asdf.mjs 
(node:11537) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
293 false
295 aborting
302 AbortError
node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is locked
    at new NodeError (node:internal/errors:371:5)
    at ReadableStream.cancel (node:internal/webstreams/readablestream:263:9)
    at cancelBody (/home/szm/Desktop/demo/node_modules/undici/lib/fetch/body.js:357:17)
    at EventEmitter.abortFetch (/home/szm/Desktop/demo/node_modules/undici/lib/fetch/index.js:291:5)
    at EventTarget.requestObject.signal.addEventListener.once (/home/szm/Desktop/demo/node_modules/undici/lib/fetch/index.js:143:18)
    at EventTarget.[nodejs.internal.kHybridDispatch] (node:internal/event_target:562:20)
    at EventTarget.dispatchEvent (node:internal/event_target:504:26)
    at abortSignal (node:internal/abort_controller:115:10)
    at AbortController.abort (node:internal/abort_controller:146:5)
    at EventTarget.Request.signal.addEventListener.once (/home/szm/Desktop/demo/node_modules/undici/lib/fetch/request.js:335:16) {
  code: 'ERR_INVALID_STATE'
}

Node.js v17.2.0
szm@pop-os:~/Desktop/demo$ npm ls undici
demo@1.0.0 /home/szm/Desktop/demo
└── undici@4.11.3

/cc @ronag

Activity

  1. ronag commented on Dec 10, 2021

    @ronag
    Member

    checking

  2. added a commit that references this issue on Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions