vi / websocat

Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions
MIT License
7k stars 272 forks source link

websocat.x86_64-unknown-linux-musl on Ubuntu is seems to end before a message is received? #218

Closed jasondborneman closed 6 months ago

jasondborneman commented 6 months ago

When I run websocat locally (OSX), it's working great. But we need it as part of a GitHub CI process to kick off a websocket call that starts some integration testing. When it runs on the GitHub Action ubuntu-latest it almost behaves as if it's ending the connection before it receives a message (or perhaps when it receives the first message??)

websocat $websocketUrl -H "Authorization: Bearer $ACCESS_TOKEN" -E -v is how we're kicking this off. The websocket url in question is a wss:// and a bit long running (>60s) so it sends a message every 30s to let us know it's processing.

Mac OSX output (with -E -v):

[INFO  websocat::lints] Auto-inserting the line mode
[INFO  websocat::stdio_threaded_peer] get_stdio_peer (threaded)
[INFO  websocat::ws_client_peer] get_ws_client_peer
[INFO  websocat::ws_client_peer] Connected to ws
{"keepalive":true}
{"keepalive":true}
{"results":...} # this is when it finishes up and gives us what we want!
[INFO  websocat::ws_peer] Received WebSocket close message
[INFO  websocat::sessionserve] Reverse finished
[INFO  websocat::sessionserve] One of directions finished

GitHub Action Runner using ubuntu-latest (with -E -v):

[INFO  websocat::lints] Auto-inserting the line mode
[INFO  websocat::ws_client_peer] get_ws_client_peer
[INFO  websocat::ws_client_peer] Connected to ws
[INFO  websocat::sessionserve] Forward finished
[INFO  websocat::sessionserve] One of directions finished

As you can see, when it works it Receives a WebSocket close message, says Reverse finished and things end. But when does not work on ubuntu-latest it connects to ws, then after a bit says Forward finished and ends the connection.

This is how I'm installing websocat on the ubunti-latest:

sudo wget -qO /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl

sudo chmod a+x /usr/local/bin/websocat

a line that checks websocat --version says it's running 1.12.0. Tried 1.11.0 as well with the same result.

Watching the service that actually runs stuff, the connection is clearly getting through and kicking our process off. Even tried running this against something faster on the backend that returns a message to the websocket earlier than 30s. In both cases we get the same behavior - no messages sent to standard out beyond the -v logging messages.

Any ideas that could help would be greatly appreciated.

jasondborneman commented 6 months ago

The plot thickens. I tried an alternate client (wscat) and.. it's behaving similarly. Ended too fast and doing no output when it runs on GitHub Action runner ubuntu-latest.

Something about running websocket commands from a github action runner must be causing this. Open to any areas to poke into or 💡 ideas of why this might be the case. I know this isn't necessarily a bug in websocat now that I've dug further but sorta at my wit's end 😬

vi commented 6 months ago

Forward finished

What is being fed to stdin in CI scenario? Maybe it's /dev/null or something like that? This should be the difference between interactive run and CI run and can affect both clients.

Are you sending any WebSocket messages or only receiving them? If you want WebSocket to only receive the messages, use something like this:

websocat $websocketUrl -H "Authorization: Bearer $ACCESS_TOKEN" -U -n -v

i.e. "unidirectional-reverse" and "do not sent close message" options.

jasondborneman commented 6 months ago

Forward finished

What is being fed to stdin in CI scenario? Maybe it's /dev/null or something like that? This should be the difference between interactive run and CI run and can affect both clients.

Are you sending any WebSocket messages or only receiving them? If you want WebSocket to only receive the messages, use something like this:

websocat $websocketUrl -H "Authorization: Bearer $ACCESS_TOKEN" -U -n -v

i.e. "unidirectional-reverse" and "do not sent close message" options.

Just receiving messages. I'll try that out, thanks!

jasondborneman commented 6 months ago

I think that did it! Thanks so much for the suggestion. I was tearing my hair out! 😄