Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions internal/mcp/session/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,26 @@ func (s *RedisStore) Get(ctx context.Context, id string) (Connection, error) {
return nil, ErrSessionNotFound
}

// First check if connection already exists in our active connections map
s.mu.RLock()
if conn, exists := s.connections[id]; exists {
s.mu.RUnlock()
// Renew TTL for both the session data and the session ID in the set
key := s.prefix + id
if err := s.client.Expire(ctx, key, s.ttl).Err(); err != nil {
s.logger.Warn("failed to renew session TTL",
zap.String("id", id),
zap.Error(err))
}
if err := s.client.Expire(ctx, s.prefix+"ids", s.ttl).Err(); err != nil {
s.logger.Warn("failed to renew session ID set TTL",
zap.String("id", id),
zap.Error(err))
}
return conn, nil
}
s.mu.RUnlock()

key := s.prefix + id
data, err := s.client.Get(ctx, key).Bytes()
if err != nil {
Expand Down