Improve LocalSessionMap NoSuchSessionException messages#486
Improve LocalSessionMap NoSuchSessionException messages#486
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| Session session = knownSessions.get(id); | ||
| if (session == null) { | ||
| SessionRemovalInfo removalInfo = removalHistory.get(id); | ||
| if (removalInfo != null) { | ||
| Instant now = Instant.now(); | ||
| if (removalInfo.isExpired(now)) { | ||
| removalHistory.remove(id, removalInfo); | ||
| } else { | ||
| long secondsAgo = Math.max(0, removalInfo.secondsSince(now)); | ||
| throw new NoSuchSessionException( | ||
| String.format( | ||
| "Session ID: %s was closed %d second(s) ago. Reason: %s", | ||
| id, secondsAgo, removalInfo.reason)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Prevent unbounded growth of removal history cache
The new removalHistory cache records every deleted session so get can report a reason (lines 132‑144), but entries are only dropped when a get call for that specific id happens or the id is re-added. In typical operation most sessions are never queried again after removal, so this map will accumulate all historic session ids despite the one-hour retention constant and will grow without bound on a long-lived grid node. Consider pruning expired entries when recording removals or with a periodic cleanup to avoid a memory leak.
Useful? React with 👍 / 👎.
Summary
LocalSessionMapso the grid can report when and why a session disappearedLocalSessionMapTestto verify the user-facing exception text contains the removal reasonTesting
Codex Task