JuliaWeb / HTTP.jl

HTTP for Julia
https://juliaweb.github.io/HTTP.jl/stable/
Other
633 stars 175 forks source link

WebSockets send can wait forever and async send seems to be broken #1063

Open bryaan opened 1 year ago

bryaan commented 1 year ago

I find myself wanting to use @async send(ws, msg) because its possible for the send to wait forever. But it is causing the error below. Without fixing this all websocket servers using this lib are broken.

│ HTTP.WebSockets.WebSocketError(HTTP.WebSockets.CloseFrameBody(1007, "Invalid UTF-8"))

bryaan commented 1 year ago

The fix for now seems to be adding a reentrantlock and doing something like this:

   try
        msg = deepcopy(msg) # So we dont modify concurrently 
        @async begin
            lock(ws.lock) do
                send(ws.client, JSON3.write(msg))
            end
        end
    catch

    end

It would be very nice if the lib did this internally. Any issues with that?

chelyabinsk commented 5 days ago

This would be great to get done