alibaba/arthas · error · IllegalStateException

The amount of async command that saving result to file can't

Error message

The amount of async command that saving result to file can't > 8

What it means

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.

Source

Thrown at core/src/main/java/com/taobao/arthas/core/shell/system/impl/JobControllerImpl.java:202

        String cacheLocation = null;
        while (tokens.hasNext()) {
            CliToken remainingToken = tokens.next();
            if (remainingToken.isText()) {
                String tokenValue = remainingToken.value();
                if ("|".equals(tokenValue)) {
                    isPipeline = true;
                    // 将管道符|之后的部分注入为输出链上的handler
                    injectHandler(stdoutHandlerChain, pipelineTokens);
                    continue;
                } else if (">>".equals(tokenValue) || ">".equals(tokenValue)) {
                    String name = getRedirectFileName(tokens);
                    if (name == null) {
                        // 如果没有指定重定向文件名,那么重定向到以jobid命名的缓存中
                        name = LogUtil.cacheDir() + File.separator + Constants.PID + File.separator + jobId;
                        cacheLocation = name;

                        if (getRedirectJobCount() == 8) {
                            throw new IllegalStateException("The amount of async command that saving result to file can't > 8");
                        }
                    }
                    redirectHandler = new RedirectHandler(name, ">>".equals(tokenValue));
                    break;
                }
            }
            if (isPipeline) {
                pipelineTokens.add(remainingToken);
            } else {
                remaining.add(remainingToken);
            }
        }
        injectHandler(stdoutHandlerChain, pipelineTokens);
        if (redirectHandler != null) {
            stdoutHandlerChain.add(redirectHandler);
            term.write("redirect output file will be: " + redirectHandler.getFilePath()+"\n");
        } else {
            stdoutHandlerChain.add(new TermHandler(term));

View on GitHub (pinned to 21cf2e9ba5)

Solutions

  1. Terminate completed redirect jobs with 'jobs' to list them then 'kill <jobId>' to free slots.
  2. Provide an explicit redirect filename so the job does not count against the cache limit: 'watch Foo bar > /tmp/out.txt &'.
  3. Reduce the number of simultaneous async redirected commands.

Example fix

// before: 9th unnamed redirect fails
$ watch Foo bar > &
// -> The amount of async command that saving result to file can't > 8

// after: use an explicit filename (bypasses cache limit) or kill old jobs first
$ jobs          # find stale jobs
$ kill 1        # free a slot
$ watch Foo bar > /tmp/watch.out &
Defensive patterns

Strategy: validation

Validate before calling

// Before starting an unnamed-redirect async job, check the count
if (jobController.getRedirectJobCount() >= 8) {
    // terminate old jobs or use an explicit filename
}

Prevention

When it happens

Trigger: 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.

Common situations: Automated batch scripts that fire many async watch/monitor commands with redirection. Long-running monitoring sessions where old redirect jobs were never terminated.

Related errors


AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14). Data as JSON: /api/errors/7ce10ee2572394e5. Report an issue: GitHub.