alibaba/arthas · error · ApiException
session not found: {}
Error message
session not found: {} What it means
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.
Source
Thrown at core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java:146
}
//no session required
if (ApiAction.INIT_SESSION.equals(action)) {
return processInitSessionRequest(apiRequest);
}
//required session
Session session = null;
boolean allowNullSession = ApiAction.EXEC.equals(action);
String sessionId = apiRequest.getSessionId();
if (StringUtils.isBlank(sessionId)) {
if (!allowNullSession) {
throw new ApiException("'sessionId' is required");
}
} else {
session = sessionManager.getSession(sessionId);
if (session == null) {
throw new ApiException("session not found: " + sessionId);
}
sessionManager.updateAccessTime(session);
}
// 标记所谓的一次性session
if (session == null) {
session = sessionManager.createSession();
session.put(ONETIME_SESSION_KEY, new Object());
}
// 请求到达这里,如果有需要鉴权,则已经在前面的handler里处理过了
// 如果有鉴权取到的 Subject,则传递到 arthas的session里
HttpSession httpSession = HttpSessionManager.getHttpSessionFromContext(ctx);
if (httpSession != null) {
Object subject = httpSession.getAttribute(ArthasConstants.SUBJECT_KEY);
if (subject != null) {
session.put(ArthasConstants.SUBJECT_KEY, subject);
}View on GitHub (pinned to 21cf2e9ba5)
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.
Example fix
// client retry logic
try {
callApi(action, sessionId, ...);
} catch (ApiException e) {
if (e.getMessage().contains("session not found")) {
sessionId = initSession(); // re-init
callApi(action, sessionId, ...);
}
} Defensive patterns
Strategy: retry
Validate before calling
// Client-side: check session is still alive before use // (no direct API; rely on INIT_SESSION + caching with expiry)
Try / catch
try {
response = callApi(action, sessionId);
} catch (ApiException e) {
if (e.getMessage().contains("session not found")) {
sessionId = initSession();
response = callApi(action, sessionId); // retry once
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 'sessionId' is required
- create api session failed
- consumer not found: {}
- SessionId is required for this operation
- Failed to create temporary session
AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14).
Data as JSON: /api/errors/44dfc42f79a73f77.
Report an issue: GitHub.