HTTP.jl
HTTP.jl copied to clipboard
WebSockets send can wait forever and async send seems to be broken
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"))
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?