{"record":{"id":"bdcb7e1d16fcae4b","repo":"alibaba/canal","slug":"stop-channel-error-bdcb7e","errorCode":null,"errorMessage":"stop channel error","messagePattern":"stop channel 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":213,"sourceCode":"            if (this.lastGetBatchMessage != null) {\n                this.lastGetBatchMessage.ack();\n            }\n        } catch (Throwable e) {\n            if (this.lastGetBatchMessage != null) {\n                this.lastGetBatchMessage.fail();\n            }\n        } finally {\n            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":195,"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#L195-L226","documentation":"Thrown by CanalRabbitMQConsumer.disconnect when channel.close() raises IOException or TimeoutException during shutdown. The channel existed but could not be closed cleanly — usually because the underlying connection was already lost or the broker did not respond to the close handshake in time.","triggerScenarios":"channel.close() at line 210 fails. Causes: broker/connection already dropped so the channel close handshake times out; concurrent disconnect; broker slow to acknowledge close.","commonSituations":"Calling disconnect during/after a network partition; broker already gone; double-disconnect where the first close tore down the connection; slow broker under load causing the close to exceed its timeout.","solutions":["Treat channel-close failures as best-effort during shutdown: log and continue rather than aborting disconnect.","Close the connection (which implicitly closes channels) if channel.close() is flaky.","Avoid calling disconnect twice; guard with a null/closed check."],"exampleFix":"// before\ntry {\n    channel.close();\n} catch (IOException | TimeoutException e) {\n    throw new CanalClientException(\"stop channel error\", e);\n}\n\n// after — best-effort close during shutdown\ntry {\n    channel.close();\n} catch (IOException | TimeoutException | AlreadyClosedException e) {\n    logger.warn(\"Error closing rabbitmq channel during disconnect\", e);\n}","handlingStrategy":"try-catch","validationCode":"if (channel == null || !channel.isOpen()) return;","typeGuard":null,"tryCatchPattern":"try {\n    channel.close();\n} catch (IOException | TimeoutException e) {\n    logger.warn(\"Error closing rabbitmq channel during disconnect\", e);\n}","preventionTips":["Treat shutdown close failures as best-effort.","Guard disconnect with isOpen()/null checks to avoid double-close.","Closing the connection implicitly closes channels if channel.close() is flaky."],"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"}