-
-
Notifications
You must be signed in to change notification settings - Fork 306
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
refactor: switch to native fetch implementation #5811
Conversation
Performance Report✔️ no performance regression detected Full benchmark results
|
cd00212
to
cb4e403
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Just mentioned in EL offline PR (#5797), we might wanna cover all error codes used here lodestar/packages/beacon-node/src/execution/engine/utils.ts Lines 39 to 40 in 59ec5fe
I can try find out when those are thrown and add them in this PR |
After looking at further error scenarios outlined here (https://betterstack.com/community/guides/scaling-nodejs/nodejs-errors/) and in Node.js docs (https://nodejs.org/api/errors.html) I think the test coverage is sufficient. The underlying http client implementation is still the same, fetch is just a higher level abstraction. These errors are hard to test for locally / in tests:
It might be good to add
|
🎉 This PR is included in v1.10.0 🎉 |
This reverts commit 3e65be7.
Motivation
With recent issues we faced using cross-fetch (#5765 and
Failed to execute 'fetch' on 'Window': Illegal invocation
) I would suggest we get rid of it and use native fetch instead as technically there is no reason not to do it.We already dropped support for node versions below 18.15.0 and native fetch is available on later versions and has to be explicitly be disabled by setting
--no-experimental-fetch
flag.Native fetch in node is still Stability: 1 but based on the requirement for it to be compatible with the browser implementation I don't expect there will be breaking changes in the future.
Advantages
Disadvantages
Errors are not that great as details are inside
cause
property which itself is of typeError
. The errors thrown by node-fetch are much better for us as they have their own error handling which is different from native fetch in browser.The error message is not detailed at all, it just says
fetch failed
, no context at all unless you look into causeDescription
Removes cross-fetch and uses native fetch implementation instead. Inconsistent errors and intransparent messages are addressed by wrapping the native fetch implementation and throwing a custom
FetchError
, similar to node-fetch error handling.Details about error handling can be found here
lodestar/packages/api/src/utils/client/fetch.ts
Line 24 in 33a0ceb
Compatibility
See Fetch_API#browser_compatibility for more details.
Closes #5765