add a wait to the loop in close

this is possibly blocking in cases where the connection is now unresponsive, and also causing timeouts which wrap this to block.