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: fix the linux patch #2703

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 8 additions & 14 deletions lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,16 +1099,12 @@ function fetchFinale (fetchParams, response) {

const byteStream = new ReadableStream({
readableStream: transformStream.readable,
async start () {
this._bodyReader = this.readableStream.getReader()
},
async pull (controller) {
// TODO(mcollina): removen this block, not sure why pull() is called twice
if (this.readableStream.locked) {
return
}

const reader = this.readableStream.getReader()

while (controller.desiredSize >= 0) {
const { done, value } = await reader.read()
const { done, value } = await this._bodyReader.read()

if (done) {
queueMicrotask(() => readableStreamClose(controller))
Expand Down Expand Up @@ -1910,8 +1906,8 @@ async function httpNetworkFetch (

// 11. Let pullAlgorithm be an action that resumes the ongoing fetch
// if it is suspended.
const pullAlgorithm = () => {
fetchParams.controller.resume()
const pullAlgorithm = async () => {
await fetchParams.controller.resume()
Comment on lines +1909 to +1910
Copy link
Contributor Author

@Uzlopak Uzlopak Feb 6, 2024

Choose a reason for hiding this comment

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

While debugging I realized that we call pullAlgorithm with an await but as pullAlgorithm is not an async function it basically "decouples" the promise logic and the await is pointless.

await pullAlgorithm(controller)

So with this change the await pullAlgorithm will actually have something to await.

}

// 12. Let cancelAlgorithm be an algorithm that aborts fetchParams’s
Expand Down Expand Up @@ -2026,9 +2022,7 @@ async function httpNetworkFetch (
// into stream.
const buffer = new Uint8Array(bytes)
if (buffer.byteLength) {
try {
fetchParams.controller.controller.enqueue(buffer)
} catch {}
fetchParams.controller.controller.enqueue(buffer)
}

// 8. If stream is errored, then terminate the ongoing fetch.
Expand All @@ -2039,7 +2033,7 @@ async function httpNetworkFetch (

// 9. If stream doesn’t need more data ask the user agent to suspend
// the ongoing fetch.
if (!fetchParams.controller.controller.desiredSize) {
if (fetchParams.controller.controller.desiredSize <= 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to MDN desiredSize can go negative if the stream is oversaturized. !(-1) is false. And if desiredSize is 0, then we know we can not push data, anyway. 0 would actually mean, that the stream is closed. So is my change correct?

return
}
}
Expand Down