Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Shared-storage topics are never freed: streaming leaks ~32 frames per page load

未关闭
#4,010 0 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 2 天内回复

@T4rk1n 已经在做这个了。

开始于 2026年9月24日。

评估

这个 Issue 还没有评估数据。

描述

bug P1 size: 3

Describe the bug

Shared-storage pub/sub topics are never removed. The streaming transport (#3930/#3931) uses one topic per page load (stream_topic(connection_id) in dash/_stream_hub.py), and each topic keeps its last buffer_size (default 32) frames. So every page load that runs a streaming callback leaves its last 32 frames in memory for the life of the process.

With LocalSharedStorage, StoreEngine._topics (dash/_shared_storage/_engine.py) is a plain dict. _topic() adds an entry on first publish, head_seq or poll, and nothing ever deletes one. Pub/sub is not persisted, so the only thing that frees them is the owner process exiting.

Measured

A streaming callback yielding 40 frames of ~50 KB, driven headless with dash_duo: 20 page loads, then the browser navigates away and we wait 40s (past DOWNLINK_GRACE and POLL_GRACE).

  • 20 _dash_stream: topics still in engine._topics
  • 640 frames still buffered (32 per topic)
  • heap grew 39.9 MB, about 2 MB per page load

A long-running app streaming figures or LLM output grows without bound.

Other backends

  • DiskcacheSharedStorage: ss:seq:<topic> / ss:msg:<topic>:<n> are written without expire. Bounded only by the cache size_limit eviction.
  • RedisSharedStorage: the seq counter and stream keys have no TTL. MAXLEN limits messages per topic, not the number of topics.

App code using ctx.shared_storage.publish/subscribe with per-session or per-run topic names leaks the same way (about 2.4 KB per empty topic on the local engine).

Expected behavior

A topic nobody uses any more is released. Some options:

  • Local engine: drop a topic once it has no subscribers or waiters and has been idle past some window.
  • Add delete_topic(topic) to BaseSharedStorage and call it when a Downlink connection is finished (the pump already knows when the browser is gone).
  • A topic ttl, matching set(..., ttl=): Redis EXPIRE, diskcache expire=, a deadline in the local engine.

Streaming and shared storage are not released yet (4.5.0rc0), so this can be fixed before 4.5.0.

Repro

import asyncio
from dash import Dash, Input, Output, html

app = Dash(__name__)
app.layout = html.Div([html.Button("go", id="btn"), html.Div(id="out")])

@app.callback(Output("out", "children"), Input("btn", "n_clicks"),
              prevent_initial_call=True)
async def cb(n):
    for i in range(40):
        await asyncio.sleep(0.01)
        yield "x" * 50_000 + f"-{i}"
    yield "done"

Load the page and click the button N times across reloads, then inspect app.shared_storage._coord.engine._topics: one _dash_stream:<connection_id> entry per page load, each holding 32 frames, long after the browser left.

主要语言
Python
星标
24.4k
派生
2.3k
平均合并
3 天 10 小时
30 天内合并 PR
24

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

plotly/dash 的其他 Issue

查看 plotly/dash 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。