Fix a race condition in http client