lib/connection.js
function(authFailHandler, err) {
    if (_status === Status.CLOSING || _status === Status.CLOSED) return;

    _socket.writeBuf = () => {};
    _socket.flush = () => {};

    //socket has been ended without error
    if (!err) {
      err = Errors.createError(
        'socket has unexpectedly been closed',
        true,
        info,
        '08S01',
        Errors.ER_SOCKET_UNEXPECTED_CLOSE
      );
    } else {
      err.fatal = true;
      this.sqlState = 'HY000';
    }

    const packetMsgs = info.getLastPackets();
    if (packetMsgs !== '') {
      err.message += '\nlast received packets:\n' + packetMsgs;
    }

    switch (_status) {
      case Status.CONNECTING:
      case Status.AUTHENTICATING:
        const currentCmd = _receiveQueue.peekFront();
        if (currentCmd && currentCmd.stack && err) {
          err.stack +=
            '\n From event:\n' +
            currentCmd.stack.substring(currentCmd.stack.indexOf('\n') + 1);
        }
        authFailHandler(err);
        break;

      default:
        _fatalError(err, false);
    }
  }
function(authFailHandler, err) {
    if (_status === Status.CLOSING || _status === Status.CLOSED) return;

    _socket.writeBuf = () => {};
    _socket.flush = () => {};

    //socket has been ended without error
    if (!err) {
      err = Errors.createError(
        'socket has unexpectedly been closed',
        true,
        info,
        '08S01',
        Errors.ER_SOCKET_UNEXPECTED_CLOSE
      );
    } else {
      err.fatal = true;
      this.sqlState = 'HY000';
    }

    const packetMsgs = info.getLastPackets();
    if (packetMsgs !== '') {
      err.message += '\nlast received packets:\n' + packetMsgs;
    }

    switch (_status) {
      case Status.CONNECTING:
      case Status.AUTHENTICATING:
        const currentCmd = _receiveQueue.peekFront();
        if (currentCmd && currentCmd.stack && err) {
          err.stack +=
            '\n From event:\n' +
            currentCmd.stack.substring(currentCmd.stack.indexOf('\n') + 1);
        }
        authFailHandler(err);
        break;

      default:
        _fatalError(err, false);
    }
  }
function ( authFailHandler , err ) { if ( _status === Status . CLOSING || _status === Status . CLOSED ) return ; _socket . writeBuf = ( ) => { } ; _socket . flush = ( ) => { } ; //socket has been ended without error if ( ! err ) { err = Errors . createError ( 'socket has unexpectedly been closed' , true , info , '08S01' , Errors . ER_SOCKET_UNEXPECTED_CLOSE ) ; } else { err . fatal = true ; this . sqlState = 'HY000' ; } const packetMsgs = info . getLastPackets ( ) ; if ( packetMsgs !== '' ) { err . message += '\nlast received packets:\n' + packetMsgs ; } switch ( _status ) { case Status . CONNECTING : case Status . AUTHENTICATING : const currentCmd = _receiveQueue . peekFront ( ) ; if ( currentCmd && currentCmd . stack && err ) { err . stack += '\n From event:\n' + currentCmd . stack . substring ( currentCmd . stack . indexOf ( '\n' ) + 1 ) ; } authFailHandler ( err ) ; break ; default : _fatalError ( err , false ) ; } }
Handle socket error.

@param authFailHandler   authentication handler
@param err               socket error
@private
Handle socket error .