websocat: race condition when piping and closing

There is a race condition when piping to Websocat : please see this two tests, using Websocat v1.0beta:

here I received the response, good :

$ printf  foo | websocat.exe - ws://127.0.0.1:9222/
{"error":{"code":-32700,"message":"Message must be a valid JSON"}}

here with the same test I did not receive the response :

$ printf  foo | websocat.exe - ws://127.0.0.1:9222/

if I repeat the test 10 times then only 3 or 4 times I receive the response…

fiddling with Wireshark I see that the close opcode flag is sent by Websocat sometimes before receiving the response of the server. if the server take time to answer then Websocat will close the connection before receiving the response. is it possible to add a delay for the response, and if no response is received in that delay then close. or maybe there is a better solution?

NB: using this solution I can close when needed and everything works fine because the race condition can never happen, but I wanted to know if it is possible to make it work with simple pipes. Thank you

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 26 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Note that --no-close --line --one-message is going to have a short version -nl1.

Re-uploaded the files. Please re-check.

do you think it can be solved, or it is by design in windows?

Not sure. I don’t have an actual Windows, so it’s not convenient to develop Windows-specific things.


For info: the bug was that main thread was exiting without waiting for completion of the additional thread that writes to stdout.