{"record":{"id":"58b32340cca830bb","repo":"apache/cassandra","slug":"max-profiling-duration-is-s-seconds-if-you-need","errorCode":null,"errorMessage":"Max profiling duration is %s seconds. If you need longer profiling, use execute command instead.","messagePattern":"Max profiling duration is (.+?) seconds\\. If you need longer profiling, use execute command instead\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/AsyncProfilerService.java","lineNumber":418,"sourceCode":"    }\n\n    public static String validateCommand(String command)\n    {\n        if (command == null || command.isBlank())\n            throw new IllegalArgumentException(\"Command can not be null or blank string.\");\n\n        return command;\n    }\n\n    /**\n     * @param duration duration of profiling\n     * @return converted string representation of duration to seconds\n     */\n    public static int parseDuration(String duration)\n    {\n        int durationSeconds = new DurationSpec.IntSecondsBound(duration).toSeconds();\n        if (durationSeconds > MAX_SAFE_PROFILING_DURATION)\n            throw new IllegalArgumentException(format(\"Max profiling duration is %s seconds. If you need longer profiling, use execute command instead.\",\n                                                      MAX_SAFE_PROFILING_DURATION));\n        return durationSeconds;\n    }\n\n    private static void maybeCreateProfilesLogDir()\n    {\n        String dir = new File(logDir).toAbsolute().toString();\n\n        if ((DatabaseDescriptor.getCommitLogLocation() != null && dir.startsWith(DatabaseDescriptor.getCommitLogLocation())) ||\n            (DatabaseDescriptor.getAccordJournalDirectory() != null && dir.startsWith(DatabaseDescriptor.getAccordJournalDirectory())) ||\n            dir.startsWith(DatabaseDescriptor.getHintsDirectory().absolutePath()) ||\n            (DatabaseDescriptor.getCDCLogLocation() != null && dir.startsWith(DatabaseDescriptor.getCDCLogLocation())) ||\n            (DatabaseDescriptor.getSavedCachesLocation() != null && dir.startsWith(DatabaseDescriptor.getSavedCachesLocation())))\n        {\n            throw new RuntimeException(\"You can not store Async-Profiler results into system Cassandra directory.\");\n        }\n\n        for (String location : StorageService.instance.getAllDataFileLocations())","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/AsyncProfilerService.java#L400-L436","documentation":"parseDuration converts a duration string (via DurationSpec.IntSecondsBound) into seconds for the profiler, but caps it at MAX_SAFE_PROFILING_DURATION because very long in-process profiling sessions risk unbounded output files and memory pressure. Longer runs must use the raw execute() command path instead.","triggerScenarios":"Calling cmd()/apply() with duration='24h' (or any duration exceeding MAX_SAFE_PROFILING_DURATION seconds) so the parsed seconds exceed the cap.","commonSituations":"Operators trying to profile an entire day; scripts converting 'infinity' or large values; confusion between the safe start/stop workflow and execute()-based long profiling.","solutions":["Reduce the requested duration to at most MAX_SAFE_PROFILING_DURATION seconds (as printed in the message)","For longer profiling, enable unsafe mode and use the execute() MBean operation with async-profiler's own arguments","Use start/stop style commands to bracket a long interval instead of a single timed run"],"exampleFix":"// before\nservice.cmd(\"start,profile,output.html\", \"30d\");\n// after\nservice.cmd(\"start,profile,output.html\", \"300s\"); // or use execute() for longer runs","handlingStrategy":"validation","validationCode":"int secs = (int)(Duration.parse(dur).toSeconds());\nif (secs > AsyncProfilerService.MAX_SAFE_PROFILING_DURATION) throw new IllegalArgumentException(\"duration too long; use execute()\");","typeGuard":null,"tryCatchPattern":"try { svc.cmd(command, duration); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Max profiling duration\")) { svc.cmd(command, \"300s\"); } else throw e; }","preventionTips":["Keep timed profiles under MAX_SAFE_PROFILING_DURATION seconds","Use start/stop bracketing or execute() for long-running profiling","Parse durations with DurationSpec in tooling to match server semantics"],"tags":["validation","duration","async-profiler"],"backgroundTag":"value-out-of-range","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"}