{"record":{"id":"400d226c97385c67","repo":"alibaba/arthas","slug":"failed-to-create-temporary-session","errorCode":null,"errorMessage":"Failed to create temporary session","messagePattern":"Failed to create temporary session","errorType":"exception","errorClass":"SessionNotFoundException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/taobao/arthas/core/command/CommandExecutorImpl.java","lineNumber":62,"sourceCode":"    private final SessionManager sessionManager;\n    private final JobController jobController;\n    private final InternalCommandManager commandManager;\n\n    public CommandExecutorImpl(SessionManager sessionManager) {\n        this.sessionManager = sessionManager;\n        this.commandManager = sessionManager.getCommandManager();\n        this.jobController = sessionManager.getJobController();\n    }\n\n    public Session getCurrentSession(String sessionId, boolean oneTimeIsAllowed) {\n        if (sessionId == null || sessionId.trim().isEmpty()) {\n            if (!oneTimeIsAllowed) {\n                throw new SessionNotFoundException(\"SessionId is required for this operation\");\n            }\n\n            Session session = sessionManager.createSession();\n            if (session == null) {\n                throw new SessionNotFoundException(\"Failed to create temporary session\");\n            }\n            session.put(ONETIME_SESSION_KEY, new Object());\n            logger.debug(\"Created one-time session {}\", session.getSessionId());\n            return session;\n        } else {\n            Session session = sessionManager.getSession(sessionId);\n            if (session == null) {\n                throw new SessionNotFoundException(\"Session not found: \" + sessionId);\n            }\n            sessionManager.updateAccessTime(session);\n            logger.debug(\"Using existing session {}\", sessionId);\n            return session;\n        }\n    }\n\n    /**\n     * 内部同步执行方法，统一处理认证和session管理\n     * ","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/core/src/main/java/com/taobao/arthas/core/command/CommandExecutorImpl.java#L44-L80","documentation":"Thrown as SessionNotFoundException by getCurrentSession when a one-time call was permitted (oneTimeIsAllowed=true) but sessionManager.createSession() returned null. This indicates the session manager refused to allocate a session — typically because a configured limit (max sessions) was reached or the manager is shut down.","triggerScenarios":"Call getCurrentSession(null/blank, true) where sessionManager.createSession() returns null. Happens when the max-session cap is hit, the manager is stopped, or resource limits prevent new session allocation.","commonSituations":"Too many concurrent sessions exhausting the configured maximum; leaked sessions never expiring; calling after Arthas shutdown has begun; memory/thread pressure causing session creation to fail.","solutions":["Increase the max-sessions limit in Arthas options.","Close/expire idle sessions so createSession can succeed (check sessionManager for active sessions).","Verify Arthas is not shutting down at call time.","Switch to passing an explicit sessionId rather than relying on one-time creation."],"exampleFix":"// before\n// relies on implicit one-time session that fails under load\nSession s = executor.getCurrentSession(null, true);\n\n// after\n// reuse a long-lived session\nSession s = sessionManager.getSession(mySid);\nif (s == null) { s = sessionManager.createSession(); mySid = s.getSessionId(); }","handlingStrategy":"retry","validationCode":"int active = sessionManager.activeSessionCount(); // pseudo\nif (active >= maxLimit) { /* expire idle sessions or raise the cap */ }","typeGuard":null,"tryCatchPattern":"try {\n    Session s = executor.getCurrentSession(null, true);\n} catch (SessionNotFoundException e) {\n    // expire/close an idle session, then retry; or reuse an existing session id\n}","preventionTips":["Close idle sessions promptly to keep below the max-session cap.","Raise the max-sessions option if workloads need more concurrency.","Avoid one-time sessions under load; reuse explicit session ids."],"tags":["session","resource-limits","command-execution"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}