Skip to content

fix: release Panel views leaked by destroyed sessions; pin image Python - #7

Open
tabedzki wants to merge 24 commits into
mainfrom
tabedzki/fix/panel-session-leak
Open

tabedzki wants to merge 24 commits into
mainfrom
tabedzki/fix/panel-session-leak

Conversation

@tabedzki

@tabedzki tabedzki commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

🤖 Human guided, AI assisted PR (using this skill). AI text below. 🤖

Refs #6, which has the full investigation and reproduction.

Problem

The production container is OOM-killed after running for a while. Every closed browser tab can leak its session. Panel registers the per-session NotificationArea in pn.state._views and only removes it through state._notifications[doc]. Panel's own Document.destroy override deletes that entry before Bokeh runs the session-destroyed callbacks, so the cleanup never runs. The orphaned entry pins the dead Document and often the whole ChannelmapGUI (about 90k Electrode objects). This happens on Panel 1.7.5 and the latest 1.9.4.

Changes

  • _release_dead_session_views(), registered with on_session_destroyed in create_app. It drops every pn.state._views entry still pointing at the dead session's document (calling _cleanup first, and still dropping the entry if that fails). It works regardless of hook order and also covers Location/BrowserInfo, which follow the same pattern in Panel.
  • Dockerfile: ENV UV_PYTHON=3.14. Unpinned, uv now picks CPython 3.15, where dracopy 2.0.0 has no wheel, so the next tagged image build would fail.

Tests

  • End-to-end: a real in-process Panel server opens and closes sessions, then asserts no _views entry survives for a destroyed Document. Fails before the fix, passes after.
  • Unit tests for the hook: only the dead document's views are dropped; no views; empty registry; missing or None document; _cleanup raising.
  • Canary (xfail(strict=True)): plain Panel without the workaround. It xfails while the bug exists and starts failing once Panel fixes it, which is the signal to remove the workaround.
  • Full suite: 530 passed.

Verification (production image vs this branch, Playwright load, -m 3500m --memory-swap 3500m)

Prod v1.4.0 This branch
Idle RSS after 40 tab sessions (no atlases), all sessions cleaned up ~1.3–1.4 GB ~660 MB
Idle RSS after 10 min atlas-heavy load, all sessions cleaned up 1,714 MB 1,135 MB
Peak RSS in that load 2,239 MB 2,248 MB

Peaks are unchanged: concurrent sessions plus large-atlas overlay computations are a separate capacity problem, tracked in #6.

Related

Assisted-by: Claude-Code:Opus-5.5

tabedzki and others added 22 commits July 8, 2026 10:41
Add [tool.pyright] venvPath/venv so pyright resolves imports against the
project's .venv, matching the installed dependencies instead of a global
environment.

Assisted-by: ClaudeCode:claude-opus-4.8
…config

chore: point pyright at the project .venv
Brainglobe atlas efficient loading + fixed memory leak
Paper fix
fixed paper figure 1 caption
fixed fig1 caption
Add machine-readable citation metadata so GitHub shows a "Cite this
repository" button. The preferred citation is the JOSS paper
(10.21105/joss.11008); the software entry points to the v1.4.0 JOSS
release archived on Zenodo (10.5281/zenodo.22850328), with the concept
DOI listed for all versions.

Builds on m-beau#45.

Assisted-by: ClaudeCode:claude-opus-5-5
…-beau#63

docs: add CITATION.cff referencing the JOSS paper and v1.4.0 release
Every closed session leaked in production: Panel registers the
per-session NotificationArea in pn.state._views and only removes it via
state._notifications[doc], which Panel's own Document.destroy override
deletes before Bokeh runs session-destroyed callbacks. The orphaned
entry pins the dead Document and often the whole ChannelmapGUI
(~90k Electrode objects), so RSS climbed to ~3.4 GB until the
container was OOM-killed.

Register _release_dead_session_views on session destroy to drop every
_views entry still pointing at the dead document. Under the same load
idle RSS after cleanup falls from ~1.3-1.4 GB to ~660 MB.

Tests: an end-to-end Panel server test (fails before, passes after),
unit tests for the hook's edge cases, and a strict-xfail canary that
starts failing once Panel fixes the bug so the workaround can go.

Refs #6

Assisted-by: ClaudeCode:claude-opus-5-5
uv downloads the newest CPython when unpinned; with 3.15 released,
`uv sync` fails because dracopy 2.0.0 has no cp315 wheel or sdist, so
the next tagged image build would fail.

Refs #6

Assisted-by: ClaudeCode:claude-opus-5-5
@tabedzki
tabedzki force-pushed the tabedzki/fix/panel-session-leak branch from a05c28e to 06137cc Compare October 16, 2026 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants