Skip to content

Conversation

@ronag
Copy link
Member

@ronag ronag commented Dec 10, 2021

Refs: #1137

@ronag ronag requested a review from szmarczak December 10, 2021 19:11
if (request.body != null) {
cancelBody(request.body, error)
if (request.body != null && isReadable(request.body?.stream)) {
request.body.stream.cancel(error)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szmarczak: We have another spec problem here... the stream might be locked at which point we are not allowed the call cancel... even though the stream is readable... ideas?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasnell I think actually there might be a bug in node's implementation. It doesn't say anything about throwing invalid state if the stream is locked when cancelling? https://streams.spec.whatwg.org/#readable-stream-cancel

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 Invalid state: ReadableStream is locked

  test: TAP
  at:
    line: 371
    column: 5
    file: node:internal/errors
    constructor: true
    function: NodeError
  stack: >
    EventEmitter.abortFetch (lib/fetch/index.js:292:26)

    EventTarget.requestObject.signal.addEventListener.once (lib/fetch/index.js:144:18)

    EventTarget.Request.signal.addEventListener.once (lib/fetch/request.js:335:16)
  type: TypeError
  code: ERR_INVALID_STATE
  tapCaught: unhandledRejection

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szmarczak also... the spec doesn't say what to do if the promise returned from cancel rejects...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the stream might be locked at which point we are not allowed the call cancel

Locking just means it's "piped" to a reader. Cancellation still should be possible.

const controller = new AbortController();
const response = await fetch('https://speed.hetzner.de/100MB.bin', {signal: controller.signal});
const reader = response.body.getReader();
console.log(response.body.locked);
controller.abort();
console.log(await reader.read()); // GoogleChrome - DOMException: The user aborted a request.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the spec doesn't say what to do if the promise returned from cancel rejects

I think it never rejects.

@codecov-commenter
Copy link

codecov-commenter commented Dec 10, 2021

Codecov Report

Merging #1138 (0db4183) into main (47eb207) will increase coverage by 0.00%.
The diff coverage is 73.33%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1138   +/-   ##
=======================================
  Coverage   94.25%   94.26%           
=======================================
  Files          40       40           
  Lines        3797     3798    +1     
=======================================
+ Hits         3579     3580    +1     
  Misses        218      218           
Impacted Files Coverage Δ
lib/fetch/body.js 99.15% <ø> (-0.02%) ⬇️
lib/fetch/index.js 81.71% <71.42%> (+0.08%) ⬆️
lib/core/util.js 98.46% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 47eb207...0db4183. Read the comment docs.

@ronag ronag merged commit 52cf266 into main Dec 13, 2021
KhafraDev pushed a commit to KhafraDev/undici that referenced this pull request Jun 23, 2022
* fix: don't cancel with invalid state

* fixup

* fixup
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
* fix: don't cancel with invalid state

* fixup

* fixup
@Uzlopak Uzlopak deleted the 1138 branch February 21, 2024 12:37
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
* fix: don't cancel with invalid state

* fixup

* fixup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants