How to get notification when a client closes a Websocket connection?
Opened this issue · 3 comments
Basically what the title says.
If the client closes the connection, Dream.send
fails with dream.log ERROR REQ 1 Async exception: (Failure "cannot write to closed writer")
.
Currently, I'm catching the exception but, preferably, there should be a cleaner way since this a generic exception.
Reporting for now: I was able to reproduce this a couple weeks ago, but ran out of time to properly precisely diagnose it. I will get back to it in the near future.
@aantron Hey! 👋 I'm running into a situation where knowing that a client closed a ws connection is critical to implement a product feature. My current approach is to store references to websocket
values (and use ~close:false
) and later try to close when Dream.send
raises an exception (as described/assumed above). Unfortunately this seems to result in broken pipes.
Do you have any pointers to where would be the best place to start implementing notification for client termination in Dream? Happy to give it a shot, if you haven't looked into this yet.
I think at the very least if would be useful to be able to run a clean up function potentially registered with Dream.websocket ~on_close
.