HTTP.jl icon indicating copy to clipboard operation
HTTP.jl copied to clipboard

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

Open bryaan opened this issue 2 years ago • 3 comments

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 avatar Jun 13 '23 21:06 bryaan

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?

bryaan avatar Jun 15 '23 20:06 bryaan