fix race condition connect