added check for closed socket race condition
added check for closed socket race condition