{"record":{"id":"1f3a3cbd98448b19","repo":"alibaba/canal","slug":"stop-connect-error-1f3a3c","errorCode":null,"errorMessage":"stop connect error","messagePattern":"stop connect error","errorType":"exception","errorClass":"CanalClientException","httpStatus":null,"severity":"warning","filePath":"connector/rabbitmq-connector/src/main/java/com/alibaba/otter/canal/connector/rabbitmq/consumer/CanalRabbitMQConsumer.java","lineNumber":221,"sourceCode":"            this.lastGetBatchMessage = null;\n        }\n    }\n\n    @Override\n    public void disconnect() {\n        if (channel != null) {\n            try {\n                channel.close();\n            } catch (IOException | TimeoutException e) {\n                throw new CanalClientException(\"stop channel error\", e);\n            }\n        }\n\n        if (connect != null) {\n            try {\n                connect.close();\n            } catch (IOException e) {\n                throw new CanalClientException(\"stop connect error\", e);\n            }\n        }\n    }\n}\n","sourceCodeStart":203,"sourceCodeEnd":226,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/connector/rabbitmq-connector/src/main/java/com/alibaba/otter/canal/connector/rabbitmq/consumer/CanalRabbitMQConsumer.java#L203-L226","documentation":"Thrown by CanalRabbitMQConsumer.disconnect when connect.close() (the underlying RabbitMQ Connection) raises an IOException during shutdown. Reached after the channel close block, so the channel was already attempted; this is the final teardown step failing.","triggerScenarios":"connect.close() at line 219 throws IOException. Causes: connection already closed/broken; broker unreachable during shutdown; an earlier channel-level failure left the connection in a bad state.","commonSituations":"Broker restarted just before shutdown; network already down; double disconnect; shutdown racing with a broker-initiated connection drop.","solutions":["Make connection close best-effort: catch and log IOException instead of propagating, since shutdown teardown failures are rarely recoverable.","Guard against double-close by checking connect != null and nulling it after close.","If channel.close() already failed, expect connection.close() may also fail — handle both leniently."],"exampleFix":"// before\nif (connect != null) {\n    try {\n        connect.close();\n    } catch (IOException e) {\n        throw new CanalClientException(\"stop connect error\", e);\n    }\n}\n\n// after — lenient shutdown, null out reference\nif (connect != null) {\n    try { connect.close(); }\n    catch (IOException e) { logger.warn(\"Error closing rabbitmq connection\", e); }\n    finally { connect = null; }\n}","handlingStrategy":"try-catch","validationCode":"if (connect == null) return;","typeGuard":null,"tryCatchPattern":"if (connect != null) {\n    try { connect.close(); }\n    catch (IOException e) { logger.warn(\"Error closing rabbitmq connection\", e); }\n    finally { connect = null; }\n}","preventionTips":["Make disconnect idempotent and null out the connection reference.","Log, do not throw, on connection-close failures during shutdown.","Expect connection.close() to also fail if channel.close() already failed."],"tags":["rabbitmq","shutdown","canal-connector","lifecycle"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}