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(fetch): spec #1295

Merged
merged 35 commits into from Mar 21, 2022
Merged

fix(fetch): spec #1295

merged 35 commits into from Mar 21, 2022

Conversation

ronag
Copy link
Member

@ronag ronag commented Mar 20, 2022

Applies some recent spec refactoring. Doesn't fix anything per se.

@codecov-commenter
Copy link

codecov-commenter commented Mar 20, 2022

Codecov Report

Merging #1295 (d0e361d) into main (6a0388f) will increase coverage by 0.12%.
The diff coverage is 66.21%.

@@            Coverage Diff             @@
##             main    #1295      +/-   ##
==========================================
+ Coverage   94.03%   94.16%   +0.12%     
==========================================
  Files          44       44              
  Lines        4107     4145      +38     
==========================================
+ Hits         3862     3903      +41     
+ Misses        245      242       -3     
Impacted Files Coverage Δ
lib/fetch/response.js 84.86% <46.66%> (-7.56%) ⬇️
lib/fetch/index.js 79.88% <69.91%> (+2.64%) ⬆️
lib/fetch/constants.js 100.00% <100.00%> (ø)
lib/fetch/headers.js 100.00% <100.00%> (ø)
lib/fetch/util.js 76.62% <100.00%> (+0.62%) ⬆️
lib/fetch/body.js 98.33% <0.00%> (-0.84%) ⬇️
lib/balanced-pool.js 100.00% <0.00%> (+2.38%) ⬆️
lib/core/errors.js 100.00% <0.00%> (+5.37%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a0388f...d0e361d. Read the comment docs.

@ronag
Copy link
Member Author

ronag commented Mar 20, 2022

@KhafraDev interested in helping out with this one?

lib/fetch/index.js Outdated Show resolved Hide resolved
@@ -1,215 +1,215 @@
'use strict'
Copy link
Member Author

Choose a reason for hiding this comment

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

@KhafraDev help here? these fail...

Copy link
Member

Choose a reason for hiding this comment

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

Okay this is quite an easy fix, but difficult to track down (my favorite)!

dataURLProcessor returns either a string or a Uint8Array

let body = stringPercentDecode(encodedBody)

body = forgivingBase64(stringBody)

So then, possibly either a spec oversight or my mistake, the body is never extracted:

body: dataURLStruct.body

Which means it's now a Uint8Array (most likely). The fix is just adding extractBody(dataURLStruct.body)[0]. All tests pass as well.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

@ronag ronag Mar 21, 2022

Choose a reason for hiding this comment

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

@KhafraDev thanks! Seems like a spec bug that it's missing extract body here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@KhafraDev KhafraDev Mar 21, 2022

Choose a reason for hiding this comment

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

This one is on us I'm pretty sure:

A body consists of:

*    A stream (a [ReadableStream](https://streams.spec.whatwg.org/#readablestream) object).

*    A source (null, a [byte sequence](https://infra.spec.whatwg.org/#byte-sequence), a [Blob](https://w3c.github.io/FileAPI/#dfn-Blob) object, or a [FormData](https://xhr.spec.whatwg.org/#formdata) object), initially null.

*    A length (null or an integer), initially null.

undici only works if the body is a stream, but it should work for all of the other types as well. dataURLProcessor returns a byte sequence body (Uint8Array in our case).

Maybe extractBody handles this?

test/node-fetch/main.js Outdated Show resolved Hide resolved
@ronag ronag marked this pull request as ready for review March 21, 2022 08:56
@ronag ronag requested a review from mcollina March 21, 2022 08:56
}
}
})
}
Copy link
Member Author

Choose a reason for hiding this comment

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

We could just freeze it but I suspect in the future we will need to be able to mutate the headers list for e.g. set-cookie.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@ronag ronag merged commit 9e5316c into main Mar 21, 2022
@RafaelGSS
Copy link
Member

RafaelGSS commented Mar 21, 2022

Hey @ronag. I've noticed this PR reduced the undici.fetch performance by almost 10%. Is that acceptable? Any guidance to solve it without reverting the changes?

This is also proven by CI: https://github.com/nodejs/undici/actions/runs/2015610582

@KhafraDev
Copy link
Member

KhafraDev commented Mar 21, 2022

I would assume so, Proxy is pretty slow (and looking at the PR one or more are created every request).

From the results it looks like more than 10%, unless I'm reading it wrong? Also a benchmark not so long ago had it at 1k request a second 😐). There is a lot of low hanging fruit I can take a stab at removing (CORs, TAO, Window/ServiceWorker stuff, etc)...

@ronag
Copy link
Member Author

ronag commented Mar 21, 2022

I’m currently prioritizing correctness and maintenance over perf. For perf I recommend the much faster undici api’s.

That being said. I’m happy to accept pr’s that improve perf as long as it doesn’t conflict with the prior priorities. Replacing proxy might be a good low hanging fruit.

KhafraDev pushed a commit to KhafraDev/undici that referenced this pull request Jun 23, 2022
* fix(fetch): spec

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fiuxp

* fixup

* fixup

* fiuxp

* fiuxp

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
* fix(fetch): spec

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fiuxp

* fixup

* fixup

* fiuxp

* fiuxp

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup
@Uzlopak Uzlopak deleted the spec4 branch February 21, 2024 12:37
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
* fix(fetch): spec

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fiuxp

* fixup

* fixup

* fiuxp

* fiuxp

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup
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

5 participants