Skip to content

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

Merged
m-beau merged 2 commits into
m-beau:mainfrom
tabedzki:tabedzki/fix/panel-session-leak
Oct 16, 2026
Merged

m-beau merged 2 commits into
m-beau:mainfrom
tabedzki:tabedzki/fix/panel-session-leak

Conversation

@tabedzki

@tabedzki tabedzki commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Refs tabedzki#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 tabedzki#6.

Related

Assisted-by: ClaudeCode:claude-opus-5-5

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
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@8a792fb). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #65   +/-   ##
=======================================
  Coverage        ?   68.03%           
=======================================
  Files           ?       19           
  Lines           ?     3013           
  Branches        ?        0           
=======================================
  Hits            ?     2050           
  Misses          ?      963           
  Partials        ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tabedzki
tabedzki marked this pull request as ready for review October 16, 2026 15:51
@m-beau
m-beau merged commit b47b768 into m-beau:main Oct 16, 2026
1 check passed
tabedzki added a commit to tabedzki/channelmap_generator that referenced this pull request Oct 17, 2026
Release candidate so the Docker image picks up the Panel session-leak fix
(m-beau#65) and the per-click gc.collect stall fix plus watchdog (m-beau#66). The
v1.4.0 image leaks ~27-30 MB per closed session; an overnight scanner
built ~160 sessions and pushed prod RSS to 4.45 GB against a 4500M cap.

CITATION.cff stays on 1.4.0, the archived JOSS release.

Assisted-by: ClaudeCode:claude-opus-5-5
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.

3 participants