Registers a callback to be invoked when the server session is closing.
Called when the server session is closing.