{"record":{"id":"cd788b068cc57f21","repo":"apache/pulsar","slug":"failed-to-close-the-channel","errorCode":null,"errorMessage":"Failed to close the channel.","messagePattern":"Failed to close the channel\\.","errorType":"exception","errorClass":"PulsarServerException","httpStatus":null,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/channel/ServiceUnitStateChannelImpl.java","lineNumber":405,"sourceCode":"                brokerRegistry = null;\n            }\n\n            if (monitorTask != null) {\n                monitorTask.cancel(true);\n                monitorTask = null;\n                log.info(\"Successfully cancelled the cleanup tasks\");\n            }\n\n            if (stateChangeListeners != null) {\n                stateChangeListeners.close();\n            }\n\n            log.info(\"Successfully closed the channel.\");\n\n        } catch (Exception e) {\n            String msg = \"Failed to close the channel.\";\n            log.error().exception(e).log(msg);\n            throw new PulsarServerException(msg, e);\n        }\n    }\n\n    private boolean validateChannelState(ChannelState targetState, boolean checkLowerIds) {\n        int order = checkLowerIds ? -1 : 1;\n        if (Integer.compare(channelState.id, targetState.id) * order > 0) {\n            return false;\n        }\n        return true;\n    }\n\n    private boolean debug() {\n        return ExtensibleLoadManagerImpl.debug(config, log);\n    }\n\n    @Override\n    public CompletableFuture<Optional<String>> getChannelOwnerAsync() {\n        if (!validateChannelState(LeaderElectionServiceStarted, true)) {","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/channel/ServiceUnitStateChannelImpl.java#L387-L423","documentation":"ServiceUnitStateChannelImpl.close failed during channel teardown (broker registry close, monitor task cancel, listener close); the original exception is wrapped in a PulsarServerException with this message.","triggerScenarios":"Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/channel/ServiceUnitStateChannelImpl.java:405 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped cause in logs; often a metadata-store disconnect during shutdown","Retry shutdown after resolving the underlying resource issue"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}