{"record":{"id":"7ce10ee2572394e5","repo":"alibaba/arthas","slug":"the-amount-of-async-command-that-saving-result-to","errorCode":null,"errorMessage":"The amount of async command that saving result to file can't > 8","messagePattern":"The amount of async command that saving result to file can't > 8","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/taobao/arthas/core/shell/system/impl/JobControllerImpl.java","lineNumber":202,"sourceCode":"        String cacheLocation = null;\n        while (tokens.hasNext()) {\n            CliToken remainingToken = tokens.next();\n            if (remainingToken.isText()) {\n                String tokenValue = remainingToken.value();\n                if (\"|\".equals(tokenValue)) {\n                    isPipeline = true;\n                    // 将管道符|之后的部分注入为输出链上的handler\n                    injectHandler(stdoutHandlerChain, pipelineTokens);\n                    continue;\n                } else if (\">>\".equals(tokenValue) || \">\".equals(tokenValue)) {\n                    String name = getRedirectFileName(tokens);\n                    if (name == null) {\n                        // 如果没有指定重定向文件名，那么重定向到以jobid命名的缓存中\n                        name = LogUtil.cacheDir() + File.separator + Constants.PID + File.separator + jobId;\n                        cacheLocation = name;\n\n                        if (getRedirectJobCount() == 8) {\n                            throw new IllegalStateException(\"The amount of async command that saving result to file can't > 8\");\n                        }\n                    }\n                    redirectHandler = new RedirectHandler(name, \">>\".equals(tokenValue));\n                    break;\n                }\n            }\n            if (isPipeline) {\n                pipelineTokens.add(remainingToken);\n            } else {\n                remaining.add(remainingToken);\n            }\n        }\n        injectHandler(stdoutHandlerChain, pipelineTokens);\n        if (redirectHandler != null) {\n            stdoutHandlerChain.add(redirectHandler);\n            term.write(\"redirect output file will be: \" + redirectHandler.getFilePath()+\"\\n\");\n        } else {\n            stdoutHandlerChain.add(new TermHandler(term));","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/core/src/main/java/com/taobao/arthas/core/shell/system/impl/JobControllerImpl.java#L184-L220","documentation":"Thrown when an async command uses output redirection to a cache file (the '>' or '>>' operator with no explicit filename) and there are already 8 such cache-redirect jobs active. Arthas caps background cache-redirect jobs at 8 to limit disk usage, since each unnamed redirect writes to a jobId-based cache directory.","triggerScenarios":"Starting more than 8 async commands with '>' or '>>' and no filename, each running in the background simultaneously, so getRedirectJobCount() hits the hard limit of 8.","commonSituations":"Automated batch scripts that fire many async watch/monitor commands with redirection. Long-running monitoring sessions where old redirect jobs were never terminated.","solutions":["Terminate completed redirect jobs with 'jobs' to list them then 'kill <jobId>' to free slots.","Provide an explicit redirect filename so the job does not count against the cache limit: 'watch Foo bar > /tmp/out.txt &'.","Reduce the number of simultaneous async redirected commands."],"exampleFix":"// before: 9th unnamed redirect fails\n$ watch Foo bar > &\n// -> The amount of async command that saving result to file can't > 8\n\n// after: use an explicit filename (bypasses cache limit) or kill old jobs first\n$ jobs          # find stale jobs\n$ kill 1        # free a slot\n$ watch Foo bar > /tmp/watch.out &","handlingStrategy":"validation","validationCode":"// Before starting an unnamed-redirect async job, check the count\nif (jobController.getRedirectJobCount() >= 8) {\n    // terminate old jobs or use an explicit filename\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use explicit redirect filenames ('> /tmp/out.txt') to avoid the cache limit.","Terminate finished redirect jobs promptly with 'kill <jobId>'.","Monitor active jobs with 'jobs' before launching new async redirects."],"tags":["async","redirect","jobs","resource-limit"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}