{"record":{"id":"44dfc42f79a73f77","repo":"alibaba/arthas","slug":"session-not-found","errorCode":null,"errorMessage":"session not found: {}","messagePattern":"session not found: (.+?)","errorType":"http","errorClass":"ApiException","httpStatus":200,"severity":"error","filePath":"core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java","lineNumber":146,"sourceCode":"            }\n\n            //no session required\n            if (ApiAction.INIT_SESSION.equals(action)) {\n                return processInitSessionRequest(apiRequest);\n            }\n\n            //required session\n            Session session = null;\n            boolean allowNullSession = ApiAction.EXEC.equals(action);\n            String sessionId = apiRequest.getSessionId();\n            if (StringUtils.isBlank(sessionId)) {\n                if (!allowNullSession) {\n                    throw new ApiException(\"'sessionId' is required\");\n                }\n            } else {\n                session = sessionManager.getSession(sessionId);\n                if (session == null) {\n                    throw new ApiException(\"session not found: \" + sessionId);\n                }\n                sessionManager.updateAccessTime(session);\n            }\n\n            // 标记所谓的一次性session\n            if (session == null) {\n                session = sessionManager.createSession();\n                session.put(ONETIME_SESSION_KEY, new Object());\n            }\n\n            // 请求到达这里，如果有需要鉴权，则已经在前面的handler里处理过了\n            // 如果有鉴权取到的 Subject，则传递到 arthas的session里\n            HttpSession httpSession = HttpSessionManager.getHttpSessionFromContext(ctx);\n            if (httpSession != null) {\n                Object subject = httpSession.getAttribute(ArthasConstants.SUBJECT_KEY);\n                if (subject != null) {\n                    session.put(ArthasConstants.SUBJECT_KEY, subject);\n                }","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java#L128-L164","documentation":"Thrown when a sessionId is provided but sessionManager.getSession() returns null — the session does not exist. This means the session was never created, was already closed, or expired due to inactivity timeout.","triggerScenarios":"Using a sessionId from a session that was closed via CLOSE_SESSION, that timed out (session expiration), from a previous Arthas lifecycle, or simply a fabricated/typo'd sessionId.","commonSituations":"Stale sessionId cached by the client after the session expired. Long gaps between API calls exceeding the session timeout. Arthas was restarted (in-process), invalidating all sessions.","solutions":["Call INIT_SESSION to obtain a fresh sessionId and use it going forward.","Ensure API calls happen within the session timeout window (configure connectionTimeout/sessionTimeout).","Handle this error in client code by automatically re-initializing the session."],"exampleFix":"// client retry logic\ntry {\n    callApi(action, sessionId, ...);\n} catch (ApiException e) {\n    if (e.getMessage().contains(\"session not found\")) {\n        sessionId = initSession();  // re-init\n        callApi(action, sessionId, ...);\n    }\n}","handlingStrategy":"retry","validationCode":"// Client-side: check session is still alive before use\n// (no direct API; rely on INIT_SESSION + caching with expiry)","typeGuard":null,"tryCatchPattern":"try {\n    response = callApi(action, sessionId);\n} catch (ApiException e) {\n    if (e.getMessage().contains(\"session not found\")) {\n        sessionId = initSession();\n        response = callApi(action, sessionId); // retry once\n    } else throw e;\n}","preventionTips":["Implement automatic session re-initialization on 'session not found'.","Call CLOSE_SESSION explicitly when done to free resources.","Keep API calls within the session timeout window."],"tags":["http-api","session","expired"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}