fix bug: if socket.timeout, close file handler