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

eof hangs using websockets #447

Closed
lucianolorenti opened this issue Sep 17, 2019 · 2 comments
Closed

eof hangs using websockets #447

lucianolorenti opened this issue Sep 17, 2019 · 2 comments

Comments

@lucianolorenti
Copy link

lucianolorenti commented Sep 17, 2019

Julia 1.2.0
HTTP.jl 0.8.6
MbedTLS.jl 0.7.0

Hello. I am having an issue using the eof function of the WebSockets.
Using the server provided in the Readme, and the following client:

julia> HTTP.WebSockets.open("ws://127.0.0.1:8081") do ws    
           @show eof(ws)
           write(ws, "Hello")           
           x = readavailable(ws)
           @show x
       end;

The client hangs.
But if I put the @show eof(ws) under the write(ws, "Hello") line, the code does not hang.

julia> HTTP.WebSockets.open("ws://127.0.0.1:8081") do ws    
           write(ws, "Hello") 
          @show eof(ws)          
           x = readavailable(ws)
           @show x
       end;

The issue happens also if the eof is called after readavailable(ws)
What am I missing?

@zhanglix
Copy link
Contributor

zhanglix commented Aug 4, 2020

It is due to eof(::TCPSocket) will hang if there is no data available to read.

eof(ws) will eventually call eof(::TCPSocket) then hang if there is no data available to read.

@quinnj
Copy link
Member

quinnj commented Jun 11, 2022

@zhanglix is correct here and is one of the main reasons, in the newly merged overhaul of the websockets code on HTTP#master, I tried to move the WebSocket object and its API away from being IO-like. i.e. there's no eof(ws) method supported anymore because it's too easy to accidentally call this and it will just block forever waiting for a message to send. We now have a much more well-defined interface for how to work with a WebSocket object (check out the docs for ?WebSocket on HTTP#master!) which should lead to a much more predictable/convenient usage.

@quinnj quinnj closed this as completed Jun 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants