Skip to content

Close oldest unactivated session at the session limit#1760

Merged
kevinherron merged 1 commit into
eclipse-milo:mainfrom
LivingLikeKrillin:fix-session-eviction-unactivated
Jun 2, 2026
Merged

Close oldest unactivated session at the session limit#1760
kevinherron merged 1 commit into
eclipse-milo:mainfrom
LivingLikeKrillin:fix-session-eviction-unactivated

Conversation

@LivingLikeKrillin

Copy link
Copy Markdown
Contributor

Summary

When the session limit (MaxSessions) was reached, SessionManager.createSession
always returned Bad_TooManySessions. OPC UA Part 4, §5.7.2 requires that the
server shall close the oldest Session that has not yet been activated before
rejecting a new request, and return Bad_TooManySessions only when every existing
Session has already been activated.

This was raised in #1759 (from Discussion #1582), where the maintainer confirmed
no work was in progress and welcomed a PR.

Changes

  • Evict the oldest unactivated session (ordered by connection time) at the limit,
    instead of unconditionally throwing Bad_TooManySessions.
  • Run the limit check, eviction, and registration under a single lock and after
    request validation, so concurrent CreateSession requests cannot exceed
    MaxSessions, and a request that later fails validation never evicts another
    client's pending session.
  • ActivateSession's created→active move takes the same lock and rejects a session
    that was evicted mid-activation (Bad_SessionIdInvalid).

Tests

  • SessionEvictionTest: evicts the oldest unactivated session; still returns
    Bad_TooManySessions when all sessions are activated; never exceeds the limit
    under a concurrent CreateSession burst.
  • Added a TestServer.create(OpcUaServerConfigLimits) overload to set MaxSessions.

Fixes #1759


Developed with AI assistance (Anthropic Claude Opus 4.8); the human contributor
reviewed, verified, and tested all changes.

When MaxSessions was reached, SessionManager.createSession always threw
Bad_TooManySessions. OPC UA Part 4, 5.7.2 requires that the server shall
close the oldest Session that has not yet been activated before rejecting
a new request, returning Bad_TooManySessions only when every existing
Session has already been activated.

Evict the oldest unactivated session (by connection time) instead. The
limit check, eviction, and registration now run under a single lock and
after request validation, so concurrent CreateSession requests cannot
exceed MaxSessions and a request that later fails validation never evicts
another client's pending session. ActivateSession's created-to-active
move takes the same lock and rejects a session evicted mid-activation.

Fixes eclipse-milo#1759

Signed-off-by: Jooyoung Jung <livinglikekrillin@gmail.com>
@kevinherron kevinherron self-requested a review June 2, 2026 13:45
@kevinherron kevinherron merged commit 7221cef into eclipse-milo:main Jun 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server does not close oldest unactivated Session at the session limit (Part 4 §5.7.2)

2 participants