alibaba/arthas · error · SessionNotFoundException
Session not found: {sessionId}
Error message
Session not found: {sessionId} What it means
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).
Source
Thrown at core/src/main/java/com/taobao/arthas/core/command/CommandExecutorImpl.java:70
}
public Session getCurrentSession(String sessionId, boolean oneTimeIsAllowed) {
if (sessionId == null || sessionId.trim().isEmpty()) {
if (!oneTimeIsAllowed) {
throw new SessionNotFoundException("SessionId is required for this operation");
}
Session session = sessionManager.createSession();
if (session == null) {
throw new SessionNotFoundException("Failed to create temporary session");
}
session.put(ONETIME_SESSION_KEY, new Object());
logger.debug("Created one-time session {}", session.getSessionId());
return session;
} else {
Session session = sessionManager.getSession(sessionId);
if (session == null) {
throw new SessionNotFoundException("Session not found: " + sessionId);
}
sessionManager.updateAccessTime(session);
logger.debug("Using existing session {}", sessionId);
return session;
}
}
/**
* 内部同步执行方法,统一处理认证和session管理
*
* @param commandLine 命令行
* @param timeout 超时时间
* @param sessionId session ID,如果为null则创建临时session
* @param authSubject 认证主体,如果不为null则应用到session
* @param userId 用户 ID,用于统计上报
* @return 执行结果
*/
@OverrideView on GitHub (pinned to 21cf2e9ba5)
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.
Example fix
// before
Session s = executor.getCurrentSession(oldSid, false);
// after
Session s;
try {
s = executor.getCurrentSession(oldSid, false);
} catch (SessionNotFoundException e) {
s = sessionManager.createSession();
oldSid = s.getSessionId();
} Defensive patterns
Strategy: try-catch
Validate before calling
Session s = sessionManager.getSession(sessionId);
if (s == null) { sessionId = sessionManager.createSession().getSessionId(); } Try / catch
try {
Session s = executor.getCurrentSession(sessionId, false);
} catch (SessionNotFoundException e) {
sessionId = sessionManager.createSession().getSessionId();
// retry with the new id
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- SessionId is required for this operation
- -32602
- Required parameter '{paramName}' cannot be empty
- {iface} missing newInstance method
- {iface} is not an interface
AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14).
Data as JSON: /api/errors/31dfc6a707d48155.
Report an issue: GitHub.