Solving race when connecting