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