dream icon indicating copy to clipboard operation
dream copied to clipboard

How to get notification when a client closes a Websocket connection?

Open teddynecsoiu opened this issue 2 years ago • 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.

teddynecsoiu avatar Mar 10 '22 19:03 teddynecsoiu

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 avatar Mar 30 '22 08:03 aantron

@aantron Hey! :wave: 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.

rizo avatar May 03 '22 18:05 rizo

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.

rizo avatar May 03 '22 18:05 rizo