-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
net, net/http, net/http/httptest: HTTP GET on local HTTP server fails with "fetch failed" on js/wasm with Node.js 18 #57613
Comments
This is probably related to the new "experimental" fetch functionality in Node 18: https://nodejs.org/de/blog/announcements/v18-release-announce/#fetch-experimental. |
OK I've confirmed that this is due to the introduction of the go/src/net/http/roundtrip_js.go Line 45 in 1e12c63
so we would short circuit the Fetch API roundtripper go/src/net/http/roundtrip_js.go Lines 55 to 57 in 1e12c63
This falls back to the fake network implementation in However, with Node 18, all of a sudden
I'm leaning towards option 1 for now as it means we can migrate to Node 18 with few changes and no net new functionality. At a later stage we could introduce a NodeJS based socket interface if we wanted to, and then reenable Would love @neelance's thoughts on a NodeJS based socket syscall interface, I assume the reason we didn't introduce one originally was because there was no Another note I want to quickly make here is that the NodeJS fetch implementation disallows the use of certain ports directly on the client (per the Fetch API spec). If we introduce |
Change https://go.dev/cl/463976 mentions this issue: |
Thanks for investigating this and figuring out the problem.
I asked Richard about that fairly recently, and he confirmed that the main reason the fake socket path was used is because that was the easiest path forward at the time. Back then, the NaCL port had the fake socket code implemented, and Node didn't support fetch. By now, with NaCL port being long gone and Node supporting fetch, it might be net simpler to start using fetch. But that is fine to investigate and consider doing if desired later. Just disabling fetch during tests with Node 18 as done in CL 463976 is good to resolve the immediate issue. Thanks. |
NodeJS 18 introduced support for the fetch API for making HTTP requests. This broke all wasm tests that were relying on NodeJS falling back to the fake network implementation in net_fake.go. Disable the fetch API on NodeJS to get tests passing. Fixes golang#57613 Change-Id: Icb2cce6d5289d812da798e07366f8ac26b5f82cb Reviewed-on: https://go-review.googlesource.com/c/go/+/463976 Reviewed-by: Evan Phoenix <evan@phx.io> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Change https://go.dev/cl/503675 mentions this issue: |
The Fetch API was meant to only be disabled in tests. Since wasm_exec.js defines a global 'process' object, it ended up being disabled anywhere that script is used. Make the heuristic stricter so that it's less likely to trigger anywhere but when testing js/wasm using Node.js. For #57613. Fixes #60808. Change-Id: Ief8def802b466ef4faad16daccefcfd72e4398b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/503675 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com>
I have done some testing and I definitely have this issue. In fact, this is not an issue just for testing / playground applications. I have created a golang based webassembly module that runs on my website and uses the REST exported by that website. It does not work. I have tested doing http gets in the webassembly to non locally based URLs. It works fine. Is there any work around for the issue for someone using the golang http package? |
Change https://go.dev/cl/611215 mentions this issue: |
Some Go packages use a local HTTP server in examples. To make these work, the js/wasm port includes:
go/src/net/net_fake.go
Line 5 in bae7d77
It works okay with Node.js 14, but fails with Node.js 18. Without it working, tests/examples in packages like compress/gzip and various others fail. This is the tracking issue this problem.
Tested at tip (79cdecc) with local patches to work around #56860 and #57516. Those issues will need to resolved first; I'm just reporting this finding earlier since I came across it while looking briefly into what's needed to make all.bash pass with Node 18.
It can be reproduced with
GOOS=js GOARCH=wasm ./all.bash
, orGOOS=js GOARCH=wasm go test -run='Example_compressingReader' compress/gzip
, or with this more standalone program:CC @golang/js, @golang/wasm, @johanbrandhorst.
The text was updated successfully, but these errors were encountered: