Infinite loop avoidance in Unexpected EOF