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

fix(ext/fetch): Fix missing check of duplex field #17192

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hawkinsw
Copy link

@hawkinsw hawkinsw commented Dec 27, 2022

WHATWG specifies that when a user gives a ReadableStream as the body as the init parameter of a Request constructor, the implementation must check whether the user has also set the duplex field to "half".

FYI: Step 39 is where the requirement is defined.

@CLAassistant
Copy link

CLAassistant commented Dec 27, 2022

CLA assistant check
All committers have signed the CLA.

@hawkinsw
Copy link
Author

Hello! Thank you so much for this awesome project! I hope that this is helpful and I hope that I followed all the proper instructions! Please let me know what I can do to clean this up so that is as helpful as possible!

Thank you again!
Will

@hawkinsw
Copy link
Author

Forgive my earlier PR with leftover print-debugging statement. Sorry!

@hawkinsw
Copy link
Author

Sorry for not leaving the tests in a happy state! I am fixing up the tests now. Sorry again! cc @bartlomieju @lucacasonato

@hawkinsw
Copy link
Author

Again, sorry about not fixing the tests the first time that I submitted the PR. The tests should be happy now! (At least they are happy on my machine)

Thanks for all the hard work you both do for the project!
Will

@hawkinsw
Copy link
Author

hawkinsw commented Jan 3, 2023

Again, sorry about not fixing the tests the first time that I submitted the PR. The tests should be happy now! (At least they are happy on my machine)

Thanks for all the hard work you both do for the project! Will

Hope you are all doing well! I just wanted to let you know that I am more than happy to make whatever changes you would like! I hope that you find this helpful!

Sincerely,
Will

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @hawkinsw, could you please run format script (tools/format.js) to make CI happy?

Also are there any WPT tests that cover this change?

@hawkinsw
Copy link
Author

hawkinsw commented Jan 3, 2023

Thanks for the PR @hawkinsw, could you please run format script (tools/format.js) to make CI happy?

I am terribly sorry -- I absolutely thought that I had already done this step! I pushed a new version of the PR. Sorry again!

Also are there any WPT tests that cover this change?

Not that I am aware of. That said, I will be happy to look and let you know what I find!

Thanks again for all your work on the project!
Will

@hawkinsw
Copy link
Author

hawkinsw commented Jan 3, 2023

Looks like we fixed some "expected" failures: https://github.com/denoland/deno/actions/runs/3832506757/jobs/6523719259#step:39:16770

I will go through and attempt to remove the "expected failure" marking from those. I may need to reach out if I can't figure out how to wrangle the test configuration.

WHATWG specifies that when a user gives a `ReadableStream` as the `body`
as the `init` parameter of a `Request` constructor, the implementation
must check whether the user has also set the `duplex` field to "half".
@hawkinsw
Copy link
Author

hawkinsw commented Jan 4, 2023

Hello @bartlomieju !! I have updated expectations.json to account for the "fixed" tests. These tests will now (properly) fail because this PR restricts the valid values of a RequestDuplex in a RequestInit to half. I find it interesting that these wpts test for a condition that is only implicitly required by the standard (i.e., that it is always an error to set the duplex to be anything other than half at this point). But, I suppose that is an issue for a different day!

I hope that this helps!
Will

@lucacasonato
Copy link
Member

We have to diverge from the spec here (this is a breaking change) as I mention in the upstream fetch spec issue. I would like to punt this issue into the future until I have time to specify the behavior of duplex: full and upstream it into the spec. This will be our default duplex field value in the future.

@hawkinsw
Copy link
Author

hawkinsw commented Jan 9, 2023

We have to diverge from the spec here (this is a breaking change) as I mention in the upstream fetch spec issue. I would like to punt this issue into the future until I have time to specify the behavior of duplex: full and upstream it into the spec. This will be our default duplex field value in the future.

@lucacasonato Thanks for the reply! I am not 100% sure what that means with respect to this particular PR. Would you like me to make it so that the possible values for the duplex field are more flexible?

Also, I was a part of some of the specification work when I was an employee at Mozilla and would love to get involved in it again. Please, please let me know if/how I can help with the fetch spec. After unearthing this minor issue, I do feel like I have a better grasp of the spec!

Thanks again for everything -- I am an admirer of you and your work!
Will

@hawkinsw
Copy link
Author

Sorry to bother, but I just wanted to check in and see if there was anything that I could do to help! Thanks for everything, @lucacasonato !!

@aapoalas
Copy link
Collaborator

@hawkinsw Can you rebase the branch? Some conflict has unfortunately arisen so I can't trigger tests on this.

@hawkinsw
Copy link
Author

hawkinsw commented Feb 12, 2023 via email

@lucacasonato
Copy link
Member

@hawkinsw Sorry for the very late reply. Let me elaborte:

A couple of months ago, Chrome wanted to ship request body streaming in fetch. Chrome did not want to support duplex streaming though (streaming both upload and download at the same time). The current version of the fetch spec specifies only this half duplex streaming. In Deno however, we have supported full duplex streaming since we added streaming support to Fetch. This meant that for the same ReadableStream request body, there would be differing behavior between Chrome and Deno.

At this point I suggested we introduce the duplex flag to the request constructor to let users explicitly specify that they were aware they were using half duplex, and to ensure that there is a path for Chrome to support full duplex in the future. The result of this was, that to use upload streaming in Chrome, users would have to specify duplex: "half" in their request constructor.

Deno however already defaulted to duplex: "full" (which is not yet specified). As such for us it doesn't make any sense to introduce the duplex flag, until we either specify duplex: "full" or we implement support for half duplex behind the duplex: "half" flag.

Additionally, because of backwards compatibility, we can't add the requirement that users must specify duplex: "full" for full duplex, because our current behavior is to default to full duplex without the flag being specified.

So what does that mean for this PR? I see two paths forward:

  1. we introduce duplex now and default it to "full" if it is not specified explicitly (going against spec), and we throw on duplex: "half" (because it is not implemented)
  2. we don't do anything until duplex: "full" is specified in the spec

I am sort of leaning towards option 2.

@andreubotella
Copy link
Contributor

andreubotella commented Feb 13, 2023

For the record, it doesn't seem like duplex: "full" will be specified in the WHATWG fetch spec anytime soon. However, WinterCG is working on a fork of the fetch spec meant for server-side runtimes which will most likely include duplex: "full" at some point.

@hawkinsw
Copy link
Author

hawkinsw commented Feb 14, 2023 via email

@bartlomieju bartlomieju added this to the 1.46 milestone Jul 18, 2024
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.

None yet

6 participants