alibaba/arthas · error · ApiException

create api session failed

Error message

create api session failed

What it means

Thrown during INIT_SESSION processing when sessionManager.createSession() returns null. A null session indicates the session manager refused to create a new session — typically because it is closed, at capacity, or in an error state. Without a session the API cannot proceed.

Source

Thrown at core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java:254

            //welcome message
            WelcomeModel welcomeModel = new WelcomeModel();
            welcomeModel.setVersion(ArthasBanner.version());
            welcomeModel.setWiki(ArthasBanner.wiki());
            welcomeModel.setTutorials(ArthasBanner.tutorials());
            welcomeModel.setMainClass(PidUtils.mainClass());
            welcomeModel.setPid(PidUtils.currentPid());
            welcomeModel.setTime(DateUtils.getCurrentDateTime());
            resultDistributor.appendResult(welcomeModel);

            //allow input
            updateSessionInputStatus(session, InputStatus.ALLOW_INPUT);

            response.setSessionId(session.getSessionId())
                    .setConsumerId(resultConsumer.getConsumerId())
                    .setState(ApiState.SUCCEEDED);
        } else {
            throw new ApiException("create api session failed");
        }
        return response;
    }

    /**
     * Update session input status for all consumer
     *
     * @param session
     * @param inputStatus
     */
    private void updateSessionInputStatus(Session session, InputStatus inputStatus) {
        SharingResultDistributor resultDistributor = session.getResultDistributor();
        if (resultDistributor != null) {
            resultDistributor.appendResult(new InputStatusModel(inputStatus));
        }
    }

    private ApiResponse processJoinSessionRequest(ApiRequest apiRequest, Session session) {

View on GitHub (pinned to 21cf2e9ba5)

Solutions

  1. Retry INIT_SESSION after confirming Arthas is still running and healthy (check arthas.log).
  2. Close unused sessions (CLOSE_SESSION) to free capacity if a session limit is the cause.
  3. Restart Arthas if the session manager is in a bad state.
Defensive patterns

Strategy: retry

Try / catch

try {
    response = initSession();
} catch (ApiException e) {
    if (e.getMessage().contains("create api session failed")) {
        // wait briefly and retry; if persistent, Arthas may be shutting down
        Thread.sleep(2000);
        response = initSession();
    }
}

Prevention

When it happens

Trigger: The SessionManager is in a closed state (Arthas is shutting down), has hit a maximum session count limit, or an internal error prevented session creation.

Common situations: Arthas is in the middle of a shutdown/detach sequence. Too many concurrent sessions exhausting resources. Session manager initialization failed earlier.

Related errors


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