Synchronize when attempting to close the websocket.