{"record":{"id":"9cb55d3b01a3f565","repo":"apache/cassandra","slug":"failed-to-close-jmx-connection","errorCode":null,"errorMessage":"Failed to close JMX connection","messagePattern":"Failed to close JMX connection","errorType":"console","errorClass":"CloseException","httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/tools/nodetool/JmxConnect.java","lineNumber":219,"sourceCode":"                AbstractCommand command = (AbstractCommand) lastParent.userObject();\n                if (command.shouldConnect())\n                    connect.run();\n                command.probe(connect.probe());\n            }\n            return new RunLast().execute(parseResult);\n        }\n\n        @Override\n        public void close() throws CloseException\n        {\n            try\n            {\n                if (connect.probe() != null)\n                    ((AutoCloseable) connect.probe()).close();\n            }\n            catch (Exception e)\n            {\n                throw new CloseException(\"Failed to close JMX connection\", e);\n            }\n        }\n\n        private static CommandLine.Model.CommandSpec lastExecutableSubcommandWithSameParent(List<CommandLine> parsedCommands)\n        {\n            int start = parsedCommands.size() - 1;\n            for (int i = parsedCommands.size() - 2; i >= 0; i--)\n            {\n                if (parsedCommands.get(i).getParent() != parsedCommands.get(i + 1).getParent())\n                    break;\n                start = i;\n            }\n            return parsedCommands.get(start).getCommandSpec();\n        }\n\n        private static class CloseException extends RuntimeException\n        {\n            public CloseException(String message, Throwable cause)","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tools/nodetool/JmxConnect.java#L201-L237","documentation":"JmxConnectionCommandInvoker.close() attempts to close the probe's AutoCloseable resource; any exception while closing is wrapped in CloseException('Failed to close JMX connection'). This typically indicates the underlying JMX connector was already dead or torn down.","triggerScenarios":"JMX server dropped mid-session so closing the connector throws IOException; the MBean server connection is stale; remote JVM terminated before close.","commonSituations":"Long-running jmx command where the node restarted; network interruption during command execution; node shutdown racing with nodetool completion.","solutions":["Check node liveness/network stability during the command; retry the command","Inspect the cause chain (CloseException's cause) for the underlying close error","This usually follows an earlier connection failure — fix connectivity first"],"exampleFix":"// before\ninvoker.execute(parseResult); // CloseException propagates\n// after\ntry { invoker.execute(parseResult); }\ncatch (JmxConnectionCommandInvoker.CloseException e) { e.getCause().printStackTrace(); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { invoker.execute(parseResult); } catch (JmxConnectionCommandInvoker.CloseException e) { log.warn(\"close failed\", e.getCause()); /* non-fatal; connection already gone */ }","preventionTips":["Avoid long-lived jmx commands across node restarts","Treat close failures as secondary — address the primary connection failure","Monitor network stability to nodes during JMX operations"],"tags":["jmx","connection","cleanup"],"backgroundTag":"broken-pipe","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}