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

Geth Websocket Connections Return 200 #21668

Closed
BisonAl opened this issue Oct 6, 2020 · 3 comments
Closed

Geth Websocket Connections Return 200 #21668

BisonAl opened this issue Oct 6, 2020 · 3 comments

Comments

@BisonAl
Copy link

BisonAl commented Oct 6, 2020

System information

Geth version: 1.9.20
OS & Version: Alpine

Running both websocket and rpc on port 8545, using the

--ws.port
8545

flag

Expected behaviour

When attempting to query the rpc endpoint over https at / and port 8545, a correct response is served.

When attempting to connect to the websocket over wss endpoint at / and port 8545, while passing through the headers:

Connection: Upgrade
Upgrade: websocket

a lasting websocket connection is made.

Actual behaviour

When attempting to query the rpc endpoint over https at / and port 8545, a correct response is served.

When attempting to connect to the websocket over wss endpoint at / and port 8545, while passing through the headers:

Connection: Upgrade
Upgrade: websocket

I'll get back a 200 response code instead, and no lasting connection made.

The same behavior was encountered with a variety of tools:

~ ❯ wscat -c wss://myethereumurl.net                    
error: Unexpected server response: 200

~ ❯ geth attach wss://myethereumurl.net
Fatal: Unable to attach to remote geth: websocket: bad handshake (HTTP status 200 OK)

~ ❯ websocat -k wss://myethereumurl.net 
websocat: WebSocketError: Received unexpected status code (200 OK)
websocat: error running

My theory is that geth is not treating this incoming request as an websocket connection, and is not switching protocols properly.

Steps to reproduce the behaviour

  • Create a geth full node on v1.9.20 with websocket and rpc served at port 8545.
  • Expose this geth node to external traffic
  • Attempt to establish a websocket connection using wss://, with a tool such as geth attach, wscat or websocat
  • See that you'll receive a 200 error code back.

Additional Note

Wondering if anyone else has ran into this, and may have some additional insight. I am not sure if this is a bug, or an expected result given the way I'm trying to interact with my node.

My setup was working on geth 1.9.13, however since then I know there's been a good deal of work done overhauling websockets. I'm wondering if there's any changes since then that could be causing this behavior, however I couldn't find any details in recent release notes.

If this is a known issue and can be solved by altering my configuration, I would greatly appreciate the insight!

@BisonAl
Copy link
Author

BisonAl commented Oct 6, 2020

Issue solved, we can close it when #21646 is merged.

On second thought, going to close this issue as a duplicate of #21525.

@BisonAl BisonAl closed this as completed Oct 6, 2020
@BrockMcCullough
Copy link

BrockMcCullough commented Jul 14, 2022

I realize this issue has been closed for a while, but I am seeing almost this exact problem again on version 1.10.20.

Attaching directly to port 8546 works without issue using web3 libraries and wscat -c ws://localhost:8546. However, using seemingly any proxy causes this issue to resurface, so far I have not been able to figure out why. Testing with both nginx and envoy has given the same result, HTTP 200 on the websocket upgrade attempt. In the nginx logs I can see the correct upgrade headers being passed, the configuration for both proxies is presumably correct (works with other services), but with both geth and bor, the websocket connections do not work.

Replication: I'm running a Geth node with the default ports. The node has been functional for a few weeks and tested (on localhost).
envoy.yaml.zip

  1. Add reverse proxy to the node, I've attached a config for envoy here that is listening on 8544 for websocket and forwarding to 8546. Can add nginx config as well, but has the same result.
  2. Run wscat -c ws://localhost:8544/ws
  3. Above will return: error: Unexpected server response: 200

Also attached are some screenshots of logs from debugging. The first is the expected 101 Switching Protocol response that is expected from the successful websocket call. This was pulled from an identical nginx configuration running on my Solana node. Next to that is the HTTP 200 being returned by Geth on the upgrade request, even with the correct headers. Any help or suggestions appreciated, going to try an older version of Geth now, then keep trying alternate configs to see what shakes loose.

From geth.service:
User=ubuntu

ExecStart=/usr/bin/geth --datadir /node_data --signer=/node_data/clef/clef.ipc --goerli --syncmode snap --http --http.api personal,eth,net,web3 --ws --ws.origins '*' --ws.api eth,net,web3

Screen Shot 2022-07-13 at 2 03 42 PM

Screen Shot 2022-07-13 at 2 01 43 PM

Also adding Envoy logs:
Screen Shot 2022-07-14 at 2 09 23 PM

@mattsavedme
Copy link

did u solve this question, i have the same issue. my geth version is 1.11.0-unstable. @BrockMcCullough

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

No branches or pull requests

4 participants
@BisonAl @BrockMcCullough @mattsavedme and others