Closed tayler-king closed 3 years ago
unnecessary complexity
the standard thing to do if doing async before using socket is set ws.isClosed=true
in the close handler and check it after async, not that complex
close:ws=>ws.isClosed=true
await async()
if(!ws.isClosed)ws.subscribe(topic)
the standard thing to do if doing async before using socket is set
ws.isClosed=true
in the close handler and check it after async, not that complexclose:ws=>ws.isClosed=true await async() if(!ws.isClosed)ws.subscribe(topic)
Does mutating the socket object passed to one handler guarantee that the object mutation will carry across to the other handles? As an example:
message
callback, attempts to subscribe to topicclose
callback is mutated, socket.isClosed
is set to true
step 1
attempts to check socket.isClosed
during its async operationits the same JS object being passed around, so yes different functions access same ws
object with updated properties
its the same JS object being passed around, so yes different functions access same
ws
object with updated properties
Great, thank you. I'll close this issue as that should suffice.
Say I have a websocket that follows this process:
This works well and fine. However in some conditions, as the socket subscription is asynchronous, the following happens:
Invalid access of closed uWS.WebSocket/SSLWebSocket.
I say the subscription is "asynchronous" for the following reasons:
socket.subscribe(topic)
once the asynchronous operation completesAs you can see, if the socket disconnects during
step 3
then attempting to callsocket.subscribe(topic)
results in an exception being thrown.Now obviously I could just handle that exception but I would much prefer if I could pre-emptively check if the socket is closed prior to calling
socket.subscribe(topic)
.Is this at all possible? From taking a quick glance at the codebase it doesn't seem so. Maybe having a
socket.isClosed
flag on socket objects would be possible?I could also track this myself, but it seems like unnecessary complexity that would possibly be better suited in the uWebSockets.js extension?