{"record":{"id":"31dfc6a707d48155","repo":"alibaba/arthas","slug":"session-not-found-sessionid","errorCode":null,"errorMessage":"Session not found: {sessionId}","messagePattern":"Session not found: (.+?)","errorType":"exception","errorClass":"SessionNotFoundException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/taobao/arthas/core/command/CommandExecutorImpl.java","lineNumber":70,"sourceCode":"    }\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     * \n     * @param commandLine 命令行\n     * @param timeout 超时时间\n     * @param sessionId session ID，如果为null则创建临时session\n     * @param authSubject 认证主体，如果不为null则应用到session\n     * @param userId 用户 ID，用于统计上报\n     * @return 执行结果\n     */\n    @Override","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/core/src/main/java/com/taobao/arthas/core/command/CommandExecutorImpl.java#L52-L88","documentation":"Thrown as SessionNotFoundException by getCurrentSession when a non-blank sessionId was supplied but sessionManager.getSession(sessionId) returned null — i.e. no session exists with that id (it was never created, expired, or was explicitly invalidated).","triggerScenarios":"Call getCurrentSession(nonBlankId, ...) with an id the manager does not recognize: a stale id from a previous run, an expired id past TTL, a mistyped/forged id, or an id from a session that was closed.","commonSituations":"Client holds a sessionId across a restart/reconnect of Arthas; session TTL elapsed between calls; multiple Arthas instances and the client hit the wrong one; typo or truncated id.","solutions":["Catch SessionNotFoundException, then create a fresh session and retry with the new id.","Verify the id was issued by this Arthas instance and is still within its TTL.","Refresh/reopen sessions after long idle periods or after Arthas restarts."],"exampleFix":"// before\nSession s = executor.getCurrentSession(oldSid, false);\n\n// after\nSession s;\ntry {\n    s = executor.getCurrentSession(oldSid, false);\n} catch (SessionNotFoundException e) {\n    s = sessionManager.createSession();\n    oldSid = s.getSessionId();\n}","handlingStrategy":"try-catch","validationCode":"Session s = sessionManager.getSession(sessionId);\nif (s == null) { sessionId = sessionManager.createSession().getSessionId(); }","typeGuard":null,"tryCatchPattern":"try {\n    Session s = executor.getCurrentSession(sessionId, false);\n} catch (SessionNotFoundException e) {\n    sessionId = sessionManager.createSession().getSessionId();\n    // retry with the new id\n}","preventionTips":["Reopen sessions after Arthas restarts or long idle periods.","Persist/refresh the session id client-side and handle expiry gracefully.","Ensure the client talks to the same Arthas instance that issued the id."],"tags":["session","ttl","api-contract"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}