Fix potential race condition in initialising the client