[whatwg/xhr] ReadableStream appears incompatible with Sync XHR (#277)

Looking at Step 12 of https://xhr.spec.whatwg.org/#the-send()-method. 

So at step 12.2, I think the task on the event-loop from where the call originates "blocks" on the "fetch" call returning a response. 

Then the problem I have run into is that as part of fetch, we have to [transmit the request body](https://fetch.spec.whatwg.org/#concept-request-transmit-body), which I think requires running code on the event-loop(although that is actually a question I've asked at https://github.com/whatwg/fetch/issues/976). 

So in other words, in order to transmit the request body of the fetch, we need to read from the stream, which, at least if the body is a user provided stream, will require running code on an event-loop. It that event-loop is the same that is currently blocking on the fetch call as part of a sync XHR, it appears to be an actual deadlock. 

I'm actually running into this very problem while integrating streams into the Servo project(see https://github.com/servo/servo/pull/25873#issuecomment-635093084). 

One potential solution, both at the level of the spec and as a practical solution, could be to add a new step prior to step 12.2(the fetch call), where one would acquire a reader, and then read all the chunks from the stream, and then use the bytes directly to transmit the body as part of the fetch. 
Although I think this could raise some issues because reading chunks from the stream could potentially result in the user stream code running, which would mean the XHR wouldn't be really "sync" anymore. 

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/xhr/issues/277

Received on Friday, 29 May 2020 04:44:40 UTC