Fix random output on socket error (reported by Aleksandrs Saveljevs, #56)