Skip to content

bug: Memory leak in SESSION_POOL, USAGE_POOL and YdocManager (with and without Redis) #21410

Closed

Description

@ashm-dev

Description

The in-memory data structures SESSION_POOL, USAGE_POOL, and YdocManager._updates grow unboundedly, causing steady RAM increase that only resolves on restart.

This affects both modes:

  • Without Redis: data accumulates in Python process RAM
  • With Redis: data accumulates in Redis RAM, because RedisDict uses hset without expire — no TTL is ever set on keys. Storing data in Redis without TTL is problematic: it defeats Redis's ability to manage memory via eviction policies, and effectively turns Redis into an ever-growing store.

Root Causes

1. USAGE_POOL not cleaned on disconnect

File: backend/open_webui/socket/main.py

On disconnect, SESSION_POOL[sid] is deleted, but USAGE_POOL entries for that sid are only cleaned via periodic_usage_pool_cleanup() on timeout. If a socket closes without timing out first, entries persist indefinitely.

@sio.event
async def disconnect(sid):
    if sid in SESSION_POOL:
        del SESSION_POOL[sid]      # ← cleaned
        # USAGE_POOL[model_id][sid] ← NOT cleaned here

2. YdocManager._updates grows without bound

File: backend/open_webui/socket/utils.py

Every document edit appends to a list that is never evicted (neither in-memory nor in Redis):

async def append_to_updates(self, document_id, update):
    if not self._redis:
        if document_id not in self._updates:
            self._updates[document_id] = []
        self._updates[document_id].append(update)  # unbounded

With Redis, rpush is used without expire — same problem.

clear_document() is only called when all users leave a document. If at least one user stays connected, updates accumulate forever.

3. RedisDict stores data without TTL

File: backend/open_webui/socket/utils.py

RedisDict uses hset/hget with no expiration. SESSION_POOL, USAGE_POOL, and MODELS data persists in Redis indefinitely. This is undesirable — data in Redis should have TTL to allow proper memory management and prevent unbounded growth.

Observed Behavior

  • RAM usage grows steadily in small increments during normal usage
  • Only returns to baseline after full application restart
  • With Redis enabled, Python process memory stabilizes but Redis memory grows instead

Expected Behavior

  • USAGE_POOL entries for a sid should be removed on disconnect
  • YdocManager._updates should have a size limit or TTL
  • RedisDict should set TTL on keys (e.g. session data should expire after disconnect + grace period)
  • Redis keys for SESSION_POOL, USAGE_POOL should have reasonable expiration times

Activity

  1. tjbck commented on Feb 16, 2026

    @tjbck
    Contributor

    Addressed in dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Sponsor
      SponsoredKunjungi sekarang
      Promo