Skip to content

deleteSession() of the InMemorySessionService does not delete the user to session mapping #687

@c0k0619

Description

@c0k0619

** Please make sure you read the contribution guide and file the issues in the rigth place. **
Contribution guide.

Describe the bug
The InMemorySessionService has the following structure for storing a session
// Structure: appName -> userId -> sessionId -> Session
private final ConcurrentMap<String, ConcurrentMap<String, ConcurrentMap<String, Session>>>
sessions;

When we do deleteSession(appName, userId, sessionId) it only removes the session but leaves back an empty map for the userId and appName

deleteSession()

What's deleted: sessionId → Session mapping
What's NOT deleted: Empty userId → {} map
What's NOT deleted: Empty appName → {} map ( This should still be fine )

Example:

BEFORE deletion:
sessions: {
"myApp": {
"user1": {
"ctx1": Session@1234
},
"user2": {
"ctx1": Session@1234
},
"user3": {
"ctx1": Session@1234
}
}
}

AFTER deletion:
sessions: {
"myApp": {
"user1": {} ← Empty map remains!
"user2": {} ← Empty map remains!
"user3": {} ← Empty map remains!
"user4": {} ← Empty map remains!
.
.
.
}
}

It can cause a potential MemoryLeak when there are a lot of users using the Agent

To Reproduce
Steps to reproduce the behavior:

  1. Install '...'
  2. Run '....'
  3. Open '....'
  4. See error

Expected behavior
An option to also delete the appName.userID map inside the InMemorySession

Screenshots
Before Deletion

Image

After Deletion

Image

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Java version: 21
  • ADK version(see maven dependency): 0.4.0

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions