Skip to content

Fix cancelPromise in ReadableStreamTee being resolved twice #1112

Merged
domenic merged 5 commits into
whatwg:mainfrom
MattiasBuelens:fix-tee-cancel-double-resolve
Mar 20, 2021
Merged

Fix cancelPromise in ReadableStreamTee being resolved twice #1112
domenic merged 5 commits into
whatwg:mainfrom
MattiasBuelens:fix-tee-cancel-double-resolve

Conversation

@MattiasBuelens

@MattiasBuelens MattiasBuelens commented Mar 19, 2021

Copy link
Copy Markdown
Collaborator

The following test is throwing an AssertionError:

let controller;
const stream = new ReadableStream({ start(c) { controller = c; } });
const [branch1, branch2] = stream.tee();

controller.error("error");

branch1.cancel().catch(_=>_);
branch2.cancel().catch(_=>_);

This can be seen in our CI logs, e.g. the latest run on master:

AssertionError: false == true
    at resolvePromise (eval at setup (/home/runner/work/streams/streams/reference-implementation/run-web-platform-tests.js:56:14), <anonymous>:6894:3)
    at eval (eval at setup (/home/runner/work/streams/streams/reference-implementation/run-web-platform-tests.js:56:14), <anonymous>:4831:5)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
  √ ReadableStream teeing: erroring a teed stream should error both branches

which refers to this line in the reference implementation:

assert(stateIsPending(p) === true);

This indicates that we're attempting to resolve an already resolved promise. Although implementers are required to ignore such attempts, we try to avoid doing this in the specification, which is why we added this check in #1102. Unfortunately, it looks like we missed a case where this assertion fails...

This PR fixes it by checking if both branches have already been canceled in "upon rejection of reader.[[closedPromise]]". If that's the case, then we will have already resolved cancelPromise and we don't need to resolve it again.

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

@MattiasBuelens

Copy link
Copy Markdown
Collaborator Author

I would also have expected this assertion failure to cause the WPT test run to fail, but instead it only logged the error without failing the tests?! Not sure why that's not working... 😕

@domenic

domenic commented Mar 19, 2021

Copy link
Copy Markdown
Member

Probably something broken in wpt-runner :(

@MattiasBuelens

Copy link
Copy Markdown
Collaborator Author

Probably something broken in wpt-runner :(

Yup, domenic/wpt-runner#22. 😉

@MattiasBuelens

Copy link
Copy Markdown
Collaborator Author

We're finding all sorts of unexpected errors today! 😁

   transform-streams/patched-global.any.html

  √ TransformStream constructor should not call setters for highWaterMark or size
  × test harness threw unexpected error
    Test named 'TransformStream constructor should not call setters for highWaterMark or size' specified 1 'cleanup' function, and 1 failed.
    null

Looks like this cleanup function is failing because we forgot to add configurable: true on the patched properties. I'll piggy-back it onto the WPT PR. 😛

@domenic
domenic merged commit 21b6acd into whatwg:main Mar 20, 2021
@domenic

domenic commented Mar 20, 2021

Copy link
Copy Markdown
Member

It looks like the WPT caught a Safari bug; do you mind filing it and updating the OP to link to it?

@MattiasBuelens

Copy link
Copy Markdown
Collaborator Author

Done! 🙂

@MattiasBuelens
MattiasBuelens deleted the fix-tee-cancel-double-resolve branch March 20, 2021 23:12
aarongable pushed a commit to chromium/chromium that referenced this pull request Apr 1, 2022
This change addresses the issue of resolving an already resolved
|cancelPromise| in ReadableStreamTee, by checking if both branches have
already been canceled. If that is the case, we will have already
resolved |cancelPromise| and don't need to resolve it again.

The corresponding specification changes are:
- whatwg/streams#1112
- whatwg/streams#1118

Bug: 1194266
Change-Id: Iccd6917c1ed98ea5677ba71e050a5f07a5b2b6ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3565500
Reviewed-by: Adam Rice <[email protected]>
Commit-Queue: Nidhi Jaju <[email protected]>
Cr-Commit-Position: refs/heads/main@{#987847}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants