{"record":{"id":"530ef40bf788fa7f","repo":"apache/seatunnel","slug":"failed-to-close-pulsar-consumer","errorCode":null,"errorMessage":"Failed to close Pulsar consumer.","messagePattern":"Failed to close Pulsar consumer\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-pulsar/src/main/java/org/apache/seatunnel/connectors/seatunnel/pulsar/source/reader/PulsarSplitReaderThread.java","lineNumber":157,"sourceCode":"        try {\n            return consumerBuilder.subscribe();\n        } catch (PulsarClientException e) {\n            throw new PulsarConnectorException(\n                    PulsarConnectorErrorCode.OPEN_PULSAR_ADMIN_FAILED,\n                    \"Failed to create pulsar consumer:\",\n                    e);\n        }\n    }\n\n    /**\n     * Closes the Pulsar consumer while exposing the connector classloader to Pulsar cleanup code.\n     */\n    private void closeConsumer() throws IOException {\n        if (consumer != null) {\n            try {\n                PulsarConfigUtil.runWithConnectorClassLoader(consumer::close);\n            } catch (Exception e) {\n                throw new IOException(\"Failed to close Pulsar consumer.\", e);\n            }\n        }\n    }\n}\n","sourceCodeStart":139,"sourceCodeEnd":162,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-pulsar/src/main/java/org/apache/seatunnel/connectors/seatunnel/pulsar/source/reader/PulsarSplitReaderThread.java#L139-L162","documentation":"Thrown by PulsarSplitReaderThread.closeConsumer as an IOException when consumer.close() fails. Close is invoked from run() and close(), so it can surface on normal task completion or cancellation. It indicates the Pulsar consumer could not gracefully unsubscribe/close, typically because the client connection is broken.","triggerScenarios":"run() finishing or close() tearing down while consumer != null and PulsarConfigUtil.runWithConnectorClassLoader(consumer::close) throws — e.g. PulsarClientException.AlreadyClosedException, client already destroyed, timeouts, or classloader errors.","commonSituations":"Broker went away mid-job so graceful close times out; reader thread already failed and consumer is stale; task cancellation racing with the reader loop's own closeConsumer; client closed earlier by another component.","solutions":["Check the IOException cause: AlreadyClosed is harmless during shutdown and can be ignored/logged at WARN.","Ensure the PulsarClient is not closed before the consumer (close consumers first, then the client).","Increase close timeout / check broker availability if the close times out.","Avoid calling reader close concurrently with the reader thread shutdown path.","If persistent, upgrade to a Pulsar client version with idempotent close behavior."],"exampleFix":"// before\nthread.close(); // may throw IOException on stale consumer\n// after\ntry {\n    thread.close();\n} catch (IOException e) {\n    if (!(e.getCause() instanceof AlreadyClosedException)) {\n        LOG.warn(\"Failed to close Pulsar consumer cleanly\", e);\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { thread.close(); } catch (IOException e) { if (!(e.getCause() instanceof PulsarClientException.AlreadyClosedException)) { LOG.warn(\"Consumer close failed\", e); } }","preventionTips":["Close consumers before closing the PulsarClient","Do not cancel the reader thread while close is in progress","Treat AlreadyClosed during shutdown as benign"],"tags":["pulsar","consumer","resource-cleanup","shutdown"],"backgroundTag":"resource-cleanup-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}