fixed socket race condition