Fix potential race condition.