Websockets and response middleware

Hello!
In a normal http request/response flow there is request/response middlewares,
but for websocket connections works only first - “request”, and the second is not called.
Is there any way to handle when websocket connection closes?
For example - to create DB session in request middleware and close it in “response” like for typical get/post… operations.