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

rpc: websocket should respect the "HTTP_PROXY" by default #27264

Conversation

oseau
Copy link
Contributor

@oseau oseau commented May 14, 2023

rpc: the default dialer for websocket should respect the proxy environment variables like "HTTP_PROXY"

By default gorilla/websocket did respect the http_proxy setting, but the newClientTransportWS function explicitly provide a websocket.Dialer without a Proxy which overwrites the default one.

Related code:

@holiman
Copy link
Contributor

holiman commented May 14, 2023

How about the other schemes then? Do they already respect the env proxy settings?

@oseau
Copy link
Contributor Author

oseau commented May 14, 2023

How about the other schemes then? Do they already respect the env proxy settings?

Yes, they already respect the env proxy settings.

The ethclient.Dial in users' codebase goes through => ethclient.DialContext => rpc.DialContext => rpc.DialOptions.

go-ethereum/rpc/client.go

Lines 197 to 212 in 9ca84e6

switch u.Scheme {
case "http", "https":
reconnect = newClientTransportHTTP(rawurl, cfg)
case "ws", "wss":
rc, err := newClientTransportWS(rawurl, cfg)
if err != nil {
return nil, err
}
reconnect = rc
case "stdio":
reconnect = newClientTransportIO(os.Stdin, os.Stdout)
case "":
reconnect = newClientTransportIPC(rawurl)
default:
return nil, fmt.Errorf("no known transport for URL scheme %q", u.Scheme)
}

In DialOptions we check for the other schemes, for "http(s)" the newClientTransportHTTP function provide a new(http.Client), which according to the doc uses a DefaultTransport with the Proxy: ProxyFromEnvironment enabled. (doc)

https://github.com/ethereum/go-ethereum/blob/9ca84e6b0b8302a0834534f262d4d2dd232640c5/rpc/http.go#L154-L156C3

I found this inconsistence behavior between http(s) and ws(s) because I tried to reach a rpc endpoint behind a proxy, the websocket connection can not be established while the http(s) requests works without problem.

@karalabe karalabe added this to the 1.11.7 milestone May 15, 2023
@karalabe karalabe merged commit 7369752 into ethereum:master May 15, 2023
1 of 2 checks passed
@oseau
Copy link
Contributor Author

oseau commented May 23, 2023

Workaround before the releasing of 1.11.7

replacing ethclient.Dial("wss://***") with

rpc.DialOptions(
	context.Background(),
	"wss://***",
	rpc.WithWebsocketDialer(
		websocket.Dialer{
			Proxy: http.ProxyFromEnvironment,
		}))

antonydenyer pushed a commit to antonydenyer/go-ethereum that referenced this pull request Jul 28, 2023
…7264)

rpc: the default dialer for websocket should respect the proxy environment variables like "HTTP_PROXY"
MoonShiesty pushed a commit to MoonShiesty/go-ethereum that referenced this pull request Aug 30, 2023
…7264)

rpc: the default dialer for websocket should respect the proxy environment variables like "HTTP_PROXY"
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
…7264)

rpc: the default dialer for websocket should respect the proxy environment variables like "HTTP_PROXY"
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
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

4 participants