{"record":{"id":"10dde16dfde4a2e1","repo":"apache/seatunnel","slug":"both-channel-and-connection-closing-failed-loggin","errorCode":null,"errorMessage":"Both channel and connection closing failed. Logging channel exception and failing with connection exception","messagePattern":"Both channel and connection closing failed\\. Logging channel exception and failing with connection exception","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-rabbitmq/src/main/java/org/apache/seatunnel/connectors/seatunnel/rabbitmq/client/RabbitmqClient.java","lineNumber":198,"sourceCode":"    }\n\n    public void close() {\n        Exception t = null;\n        try {\n            if (channel != null && channel.isOpen()) {\n                channel.close();\n            }\n        } catch (IOException | TimeoutException e) {\n            t = e;\n        }\n\n        try {\n            if (connection != null && connection.isOpen()) {\n                connection.close();\n            }\n        } catch (IOException e) {\n            if (t != null) {\n                log.warn(\n                        \"Both channel and connection closing failed. Logging channel exception and failing with connection exception\",\n                        t);\n            }\n            t = e;\n        }\n        if (t != null) {\n            throw new RabbitmqConnectorException(\n                    CLOSE_CONNECTION_FAILED,\n                    String.format(\n                            \"Error while closing RMQ connection with queue %s at %s\",\n                            config.getQueueName(), config.getHost()),\n                    t);\n        }\n    }\n\n    /** Declare the queue using configuration defaults. */\n    public void setupQueue() throws IOException {\n        if (StringUtils.isNotEmpty(config.getQueueName())) {","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-rabbitmq/src/main/java/org/apache/seatunnel/connectors/seatunnel/rabbitmq/client/RabbitmqClient.java#L180-L216","documentation":"RabbitmqClient.close() closes channel then connection, keeping the first throwable in 't'. If closing the connection also fails and a channel exception was already captured, it logs the channel exception with this warning and continues to throw/report the connection exception, so neither failure is silently lost.","triggerScenarios":"close() is invoked while both channel.close() and connection.close() throw IOException — e.g. broker already unreachable — and the channel exception 't' is non-null when the connection close fails.","commonSituations":"RabbitMQ broker going down while the task is being cancelled; network partition during shutdown; closing a client whose connection was already dropped.","solutions":["Check the logged channel exception and the propagated connection exception to identify the broker/network problem","Verify RabbitMQ broker health and network connectivity at shutdown","If both exceptions are always 'already closed', guard close with isOpen/state checks or make close idempotent and ignore AlreadyClosedException"],"exampleFix":"// before\ntry { channel.close(); } catch (IOException e) { t = e; }\ntry { connection.close(); } catch (IOException e) { ... }\n// after\nif (channel != null && channel.isOpen()) channel.close();\nif (connection != null && connection.isOpen()) connection.close();","handlingStrategy":"try-catch","validationCode":"// preflight: connection must be open and reachable before use\nif (connection == null || !connection.isOpen()) throw new IllegalStateException(\"rabbitmq connection not open\");","typeGuard":"static boolean usable(com.rabbitmq.client.Connection c) { return c != null && c.isOpen(); }","tryCatchPattern":"try { client.close(); } catch (Exception e) { /* close reports one exception; channel exception logged earlier */ log.warn(\"rabbitmq close partial failure\", e); }","preventionTips":["Check broker health before stopping jobs","Make close idempotent with isOpen checks","Avoid closing during network partitions; rely on engine retry","Keep rabbitmq client and connector versions aligned"],"tags":["rabbitmq","shutdown","network"],"backgroundTag":"connection-refused","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}