Skip to content

fix(fetch): spec#1295

Merged
ronag merged 35 commits intomainfrom
spec4
Mar 21, 2022
Merged

fix(fetch): spec#1295
ronag merged 35 commits intomainfrom
spec4

Conversation

@ronag
Copy link
Copy Markdown
Member

@ronag ronag commented Mar 20, 2022

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

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 20, 2022

Codecov Report

❌ Patch coverage is 66.21622% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.16%. Comparing base (6a0388f) to head (d0e361d).
⚠️ Report is 2078 commits behind head on main.

Files with missing lines Patch % Lines
lib/fetch/index.js 69.91% 34 Missing ⚠️
lib/fetch/response.js 46.66% 16 Missing ⚠️
Additional details and impacted files
@@            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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ronag
Copy link
Copy Markdown
Member Author

ronag commented Mar 20, 2022

@KhafraDev interested in helping out with this one?

Comment thread lib/fetch/index.js Outdated
Comment thread test/fetch/data-uri.js
@@ -1,215 +1,215 @@
'use strict'
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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?

Comment thread test/node-fetch/main.js Outdated
@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
Comment thread lib/fetch/response.js
}
}
})
}
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

5 participants