Fixed bug looping over a closed socket.

#SWAG