-
Notifications
You must be signed in to change notification settings - Fork 748
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
Web3.js cannot handle chunked transfer encodings #1418
Comments
Oof. This is awful.
|
Both 1 and 2 are logical. Could we revert to the working version of
node-fetch in short-term?
…On Fri, Jul 21, 2023, 12:35 a.m. Steven Luscher ***@***.***> wrote:
Oof. This is awful.
1. I think we're basically just going to drop support for any version
of Node prior to 18 LTS, which would fix this problem. fetch is
supported natively there.
2. In general, we need to junk this transport and provide an HTTP/2
compatible transport to folks running web3.js in Node.
—
Reply to this email directly, view it on GitHub
<#1418 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AECOQHJLJHNR7QL4YOZUTKTXRIWLPANCNFSM6AAAAAA2SEPRY4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I'm trying to remember why we upgraded, and I have a bad feeling it was because of a security advisory. |
Related: #1255 (comment) |
That's unfortunate. So what's the path forward? Will web3js be enforcing a Node 18+? |
Isn't the solution for RPCs to do this? From the release notes for
cc/ @linuskendall |
We're looking into changes on our end to work around it, yes. But RPC providers shouldn't have to. Chunked transfer encodings are part of the HTTP 1.1 spec, which has been the standard for well over a decade now. This limits RPC providers from exploring certain latency optimizations. |
@linuskendall: Oh? Doesn't the spec require that the final chunk be zero length, followed by an empty line?
https://datatracker.ietf.org/doc/html/rfc9112#chunked.encoding |
Ah ok, I misread this. Let me see if we can make a change to support this on our end. Why wouldn't this cause problems for other clients though? |
|
What I mean is that Postman, rust clients, golang clients, native fetch, axios, and other clients all handle our responses without any issue. It would surprise me that only node-fetch is spec-compliant. |
When you get to be my age, it becomes very difficult to feign surprise at such things. Anyway, the next version of web3.js absolutely will not use
|
So, two things we are seeing:
Now standards compliant means very little on the web ... The workaround seems to be to disable chunked encoding for http/1.1? That doesnt feel great. After reviewing this I dont think node-fetch is doing the right thing either. |
Response headers, @linuskendall? The problem isn’t with the headers, it’s with the response body. The body has to end with a zero-length chunk, followed by an empty line, before the socket close, or the close is considered premature. |
We're seeing the same issue. I was wondering if there was a timeline for a fix, so that we can implement a workaround if need be |
# Summary Folks are having trouble using the `node-fetch` polyfill with certain RPC providers that: * use chunked-transfer encoding * don't send a zero-sized chunk before closing the socket `node-fetch` doesn't like this, and fatals. One easy thing we can do while we figure this all out is to use the _native_ `fetch()` API included in Node 18+ by default and 17.5+ behind an experimental flag. Fixes #1418 in Node 18+. # Test Plan CI run.
Who here is running their app in Node 18+? What are your thoughts on upgrading to #1447? |
Yeah I know, I guess the point was "responses". Let me double check the responses again, but last I checked we were sending standards compliant chunks. |
So @steveluscher you previously reported this:
This this is the current behaviour of node-fetch. The spec says:
So there are two options. Either chunk-size 0 OR trailer section (your "0" I guess right?)) followed by Now in our responses I see: What i am seeing is Which is basically the very last chunk is a 0 length chunk (chunk-size 0) followed by \r\n. Exactly as per spec. It looks like the |
I don't think node-fetch is spec compliant and I think they've got it wrong :) |
Oooh. What's that tool, @linuskendall? |
It's capture traffic via tcpdump and illustrated in wireshark :) Wireshark is great for this type of thing. |
@linuskendall, can you toss me a URL that produces one of these chunked responses so that I can poke and prod at it with |
# Summary Folks are having trouble using the `node-fetch` polyfill with certain RPC providers that: * use chunked-transfer encoding * don't send a zero-sized chunk before closing the socket `node-fetch` doesn't like this, and fatals. One easy thing we can do while we figure this all out is to use the _native_ `fetch()` API included in Node 18+ by default and 17.5+ behind an experimental flag. Fixes #1418 in Node 18+. # Test Plan CI run.
🎉 This issue has been resolved in version 1.78.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@peroxy, @linuskendall, and I found the root of this problem: node-fetch/node-fetch#1767 In short, if you use Solutions include:
|
Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up. |
Overview
Web3js throws an error when it processes a response from an RPC server with chunked transfer encoding:
Invalid response body while trying to fetch [...]: Premature close
. This happens because web3js is bundling a bad version of node-fetch. The bad version of node-fetch is 2.6.12 and later versions are also impacted. Version 2.6.7 does not have this problem.Here is the bug in node-fetch: node-fetch/node-fetch#1219
It's critical to support chunked transfer encodings since its part of the HTTP/1.1 spec. This bug is very limiting for RPC providers such as ourselves (Helius) trying to make performance optimizations.
Web3js users impacted by this bug can workaround by installing version 2.6.7 and overriding the
fetch
setting of the Connection object:Steps to reproduce
Transfer-Encoding: chunked
. Alternatively you can use Helius RPCs, but we will soon be changing it due to this issue. You're welcome to create a key for free at https://dev.helius.xyz.1.78.0
and runnpm install
.new Connection('https://rpc.helius.xyz?api-key-here')
)Description of bug
All details provided in the overview.
The text was updated successfully, but these errors were encountered: