alibaba/canal · error · CanalParseException

illegal connection is null

Error message

illegal connection is null

What it means

MysqlEventParser.afterDump(ErosaConnection) immediately throws CanalParseException("illegal connection is null") if the connection argument is null. This guards the post-dump cleanup path (disconnecting metaConnection) against a null connection that would otherwise NPE on the instanceof check below.

Source

Thrown at parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/MysqlEventParser.java:139

            if (tableMetaTSDB != null && tableMetaTSDB instanceof DatabaseTableMeta) {
                ((DatabaseTableMeta) tableMetaTSDB).setConnection(metaConnection);
                ((DatabaseTableMeta) tableMetaTSDB).setFilter(eventFilter);
                ((DatabaseTableMeta) tableMetaTSDB).setBlackFilter(eventBlackFilter);
                ((DatabaseTableMeta) tableMetaTSDB).setSnapshotInterval(tsdbSnapshotInterval);
                ((DatabaseTableMeta) tableMetaTSDB).setSnapshotExpire(tsdbSnapshotExpire);
                ((DatabaseTableMeta) tableMetaTSDB).init(destination);
            }

            tableMetaCache = new TableMetaCache(metaConnection, tableMetaTSDB);
            ((LogEventConvert) binlogParser).setTableMetaCache(tableMetaCache);
        }
    }

    protected void afterDump(ErosaConnection connection) {
        super.afterDump(connection);

        if (connection == null) {
            throw new CanalParseException("illegal connection is null");
        }

        if (!(connection instanceof MysqlConnection)) {
            throw new CanalParseException("Unsupported connection type : " + connection.getClass().getSimpleName());
        }

        if (metaConnection != null) {
            try {
                metaConnection.disconnect();
            } catch (IOException e) {
                logger.error("ERROR # disconnect meta connection for address:{}", metaConnection.getConnector()
                    .getAddress(), e);
            }
        }
    }

    public void start() throws CanalParseException {
        if (runningInfo == null) { // 第一次链接主库

View on GitHub (pinned to 87be50e876)

Solutions

  1. Ensure buildErosaConnection() returns a non-null connection before the dump loop starts.
  2. Avoid nulling the connection field before afterDump completes; order stop()/cleanup after the dump finishes.
  3. If extending MysqlEventParser, do not pass null to super.afterDump().
Defensive patterns

Strategy: validation

Validate before calling

if (connection == null) {
    throw new IllegalArgumentException("afterDump called with null connection; check parser lifecycle wiring");
}

Prevention

When it happens

Trigger: afterDump() is invoked with a null ErosaConnection — typically a lifecycle/bug where the parser's connection was never built or was cleared before cleanup ran.

Common situations: A bug in a custom parser subclass overriding buildErosaConnection()/the dump loop; premature stop()/resource clearing racing with afterDump; misconfigured HA failover that nulls the connection mid-cycle.

Related errors


AI-assisted analysis of alibaba/canal@87be50e876 (2026-08-14). Data as JSON: /api/errors/acea0d2170bce566. Report an issue: GitHub.