Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should cancelation error from UnderlyingSource be transferred too? #1259

Open
saschanaz opened this issue Feb 24, 2023 · 1 comment
Open

Comments

@saschanaz
Copy link
Member

b = new ReadableStream({
    cancel() {
      throw new Error("Hello");
    }
})
transferred = structuredClone(b, { transfer: [b] })

// This resolves as it never gets the error message back, with its port immediately closed
transferred.cancel();

Couldn't find a relevant discussion, but WPT explicitly tests it to not wait for the underlying source cancel. What was the reason behind it?

I don't have a good argument against the current behavior, just out of curiosity.

@ricea
Copy link
Collaborator

ricea commented Feb 27, 2023

The short answer is that it's because transferable streams are implemented using a pipe, and pipes propagate cancellation without waiting.

Elaborating a bit, what we have is

original ---pipe---> writable <==CRIT==> transferred

(where "CRIT" means cross-realm identity transform). The internal pipe is invisible to developers, except to the extent that it dictates the semantics.

When transferred is cancelled, this is propagated back by erroring writable. Erroring is a synchronous operation, so there's no opportunity to wait.

When the pipe sees the writable is errored, it propagates it back by cancelling the original stream. Because writable is already errored, the results of cancellation cannot be propagated back up the pipe.

See also #976.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants