Fork me on GitHub
#pedestal
<
2021-07-03
>
Fabim13:07:37

I am using the official pedestal web-socket example code. How do I retrieve the send-ch when the client closes the connection? Unfortunately the :on-close of ws-path only has a num-code and not the ws-session and the send-ch like the :on-connect https://github.com/pedestal/pedestal/blob/a72c7a274af0e60ba42a18d859f7c6fe9314130e/samples/jetty-web-sockets/src/jetty_web_sockets/service.clj#L61

souenzzo15:07:55

Hey Fabim After study a bit the interface, I see that even on jetty we don't have the instance. I believe that this is because when the close event occours, the Session already do not exists anymore. For advanced usages, you can take a look at listener-fn and make-ws-listener https://github.com/pedestal/pedestal/blob/master/jetty/src/io/pedestal/http/jetty/websockets.clj#L125

Fabim16:07:16

@U2J4FRT2T Thanks for your answer. Since the session is not returned, it’s hard to find the corresponding send-ch and to close it. I’m curious if there is a good way of cleaning up the connections at :on-close (ideally using interceptors). Other web-socket solutions like chord.http-kit send a message on close, but I’m not sure how to integrate them in the pedestal ws-routing.

souenzzo13:07:13

A practical response: You don't need to implement close methods You will always need an ping method, to find disconnected clients (due no-internet or something like) In this ping routine, you will close/cleanup the closed channels

Fabim13:07:03

Ah interesting, thanks. Makes sense, I was assuming I can rely on a on-close message.

souenzzo13:07:54

Another close trigger is when you are writing a response but it throws a "closed stream" error. I worked with websockes about 4 years ago, I don't remember everything well. But as far I remember, most of our sockets close came from write errors