code: function(self) {
      return function(err, avoidThrowError) {
        if (_status === Status.CLOSING || _status === Status.CLOSED) {
          socketErrorDispatchToQueries(err);
          return;
        }
        const mustThrowError = _status !== Status.CONNECTING;
        _status = Status.CLOSING;
  
        //prevent executing new commands
        _addCommand = _addCommandDisabled;
  
        if (_socket) {
          _socket.removeAllListeners('error');
          _socket.removeAllListeners('timeout');
          _socket.removeAllListeners('close');
          _socket.removeAllListeners('data');
          if (!_socket.destroyed) _socket.destroy();
          _socket = undefined;
        }
        _status = Status.CLOSED;
  
        const errorThrownByCmd = socketErrorDispatchToQueries(err);
        if (mustThrowError) {
          if (self.listenerCount('error') > 0) {
            self.emit('error', err);
            self.emit('end');
            _clear();
          } else {
            self.emit('end');
            _clear();
            //error will be thrown if no error listener and no command did throw the exception
            if (!avoidThrowError && !errorThrownByCmd) throw err;
          }
        } else {
          _clear();
        }
      };
    }
docs: Fatal unexpected error : closing connection, and throw exception.
  
  @param self    current connection
  @private