code: public SQLException handleIoException(Exception initialException) {
      boolean mustReconnect;
      boolean driverPreventError = false;
  
      if (initialException instanceof MaxAllowedPacketException) {
        mustReconnect = ((MaxAllowedPacketException) initialException).isMustReconnect();
        driverPreventError = !mustReconnect;
      } else {
        mustReconnect = writer.exceedMaxLength();
      }
  
      if (mustReconnect) {
        try {
          connect();
        } catch (SQLException queryException) {
          connected = false;
          return new SQLNonTransientConnectionException(initialException.getMessage()
              + "\nError during reconnection" + getTraces(), CONNECTION_EXCEPTION.getSqlState(),
              initialException);
        }
  
        try {
          resetStateAfterFailover(getMaxRows(), getTransactionIsolationLevel(), getDatabase(),
              getAutocommit());
        } catch (SQLException queryException) {
          return new SQLException("reconnection succeed, but resetting previous state failed",
              UNDEFINED_SQLSTATE.getSqlState() + getTraces(), initialException);
        }
  
        return new SQLTransientConnectionException("Could not send query: query size is >= to max_allowed_packet ("
            + writer.getMaxAllowedPacket() + ")" + getTraces(), UNDEFINED_SQLSTATE.getSqlState(),
            initialException);
      }
      if (!driverPreventError) {
        connected = false;
      }
      return new SQLNonTransientConnectionException(initialException.getMessage() + getTraces(),
          driverPreventError ? UNDEFINED_SQLSTATE.getSqlState() : CONNECTION_EXCEPTION.getSqlState(),
          initialException);
  
    }
docs: Handle IoException (reconnect if Exception is due to having send too much data, making server
  close the connection.
  
  <p>There is 3 kind of IOException :</p>
  <ol>
  <li> MaxAllowedPacketException :
  without need of reconnect : thrown when driver don't send packet that would have been too big
  then error is not a CONNECTION_EXCEPTION</li>
  <li>packets size is greater than max_allowed_packet (can be checked with
  writer.isAllowedCmdLength()). Need to reconnect</li>
  <li>unknown IO error throw a CONNECTION_EXCEPTION</li>
  </ol>
  
  @param initialException initial Io error
  @return the resulting error to return to client.