Additional fix for #236: make sure the client is stopped before executing the closing code in a different thread to fail fast