Fix bug with io error 'unexpected EOF'