binarywang/WxJava · warning · TooManyActiveSessionsException
createSession: Too many active sessions
Error message
createSession: Too many active sessions
What it means
StandardSessionManager.createSession throws TooManyActiveSessionsException when the number of live sessions is at or above maxActiveSessions (rejectedSessions is incremented first). This caps memory use in high-concurrency messaging scenarios. A null sessionId is also rejected earlier in the same method with a different IllegalStateException.
Source
Thrown at weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSessionManager.java:145
@Override
public InternalSession findSession(String id) {
if (id == null) {
return null;
}
return this.sessions.get(id);
}
@Override
public InternalSession createSession(String sessionId) {
if (sessionId == null) {
throw new IllegalStateException
(SM.getString("sessionManagerImpl.createSession.ise"));
}
if ((this.maxActiveSessions >= 0) &&
(getActiveSessions() >= this.maxActiveSessions)) {
this.rejectedSessions++;
throw new TooManyActiveSessionsException(
SM.getString("sessionManagerImpl.createSession.tmase"),
this.maxActiveSessions);
}
// Recycle or create a Session instance
InternalSession session = createEmptySession();
// Initialize the properties of the new session and return it
session.setValid(true);
session.setCreationTime(System.currentTimeMillis());
session.setMaxInactiveInterval(this.maxInactiveInterval);
session.setId(sessionId);
this.sessionCounter++;
return session;
}
View on GitHub (pinned to 1c43293a3c)
Solutions
- Raise maxActiveSessions on the StandardSessionManager to match expected peak concurrency.
- Lower maxInactiveInterval so idle sessions expire and free capacity sooner.
- Ensure sessions are invalidated when flows complete rather than relying solely on timeout.
- Monitor rejectedSessions and active session count to size the cap correctly.
Example fix
// before StandardSessionManager mgr = new StandardSessionManager(); // default limits, rejects under load // after mgr.setMaxActiveSessions(10000); mgr.setMaxInactiveInterval(600); // 10 min idle expiry
Defensive patterns
Strategy: try-catch
Validate before calling
int active = sessionManager.getActiveSessions();
if (active >= sessionManager.getMaxActiveSessions()) {
// evict idle sessions or shed load before creating
log.warn("Session cap reached: {} / {}", active, sessionManager.getMaxActiveSessions());
} Try / catch
try {
return sessionManager.createSession(sessionId);
} catch (TooManyActiveSessionsException e) {
// shed load, retry after backoff, or increase cap
log.warn("Too many sessions, shedding", e);
throw e;
} Prevention
- Size maxActiveSessions to peak expected unique concurrent users.
- Lower maxInactiveInterval so idle sessions free capacity sooner.
- Invalidate sessions when flows complete instead of waiting for timeout.
- Monitor rejectedSessions to detect sustained cap pressure.
When it happens
Trigger: More concurrent unique users (each needing a session) than maxActiveSessions are active simultaneously; sessions are not expiring/being evicted fast enough to make room.
Common situations: A traffic spike on a public WeChat account/miniapp creating many simultaneous user sessions; maxInactiveInterval too long so sessions accumulate; a leak where sessions are created but never invalidated.
Related errors
- getAttributeNames: Session already invalidated
- setAttribute: Session [{0}] has already been invalidated
- 不支持的http执行器类型:{requestType}
- 不支持的http执行器类型:{requestType}
- 不支持的http执行器类型:
AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14).
Data as JSON: /api/errors/e00c80e94c0a41f3.
Report an issue: GitHub.