Skip to content

fix(tradingview-lightweight): release by= partition tables on close - #1429

Open
dsmmcken wants to merge 3 commits into
mainfrom
dmckenzie_tvl_partition_close
Open

dsmmcken wants to merge 3 commits into
mainfrom
dmckenzie_tvl_partition_close

Conversation

@dsmmcken

@dsmmcken dsmmcken commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

For a by= chart, the client fetches one table per partition key with PartitionedTable.getTable(key). Those tables are client-owned exports: closing the widget or the PartitionedTable doesn't release them. Each time a by= chart was closed or reconnected, its per-key tables stayed open on the server until the session ended.

Changes in TradingViewChartModel:

  • Track the per-key tables and release them together with the widget once every retired subscription has drained, so no in-flight snapshot is cancelled. This includes snapshots of an older, superseded subscription, such as a direct fallback after a failed downsample.
  • If getTable or the PartitionedTable fetch resolves after close(), release the result instead of registering it. Previously both leaked, and the key table was also subscribed after close.
  • subscribeTable does nothing after close(), so an async fallback can't open a subscription that is never retired.

Unit tests cover each case.

Found while checking that the by= performance issues fixed in #1428 for plotly-express don't show up in TVL. They don't, but this leak turned up along the way.

Per-key tables from PartitionedTable.getTable are client-owned exports;
neither the widget close nor PartitionedTable.close() releases them.
Close them in close(), and release key tables or the partitioned table
that resolve after close() instead of registering them.
@github-actions

Copy link
Copy Markdown

tradingview-lightweight docs preview (Available for 14 days)

A key table can still have a snapshot in flight on a superseded
subscription (e.g. a direct fallback after a failed downsample, retired
by the next successful one). Release key tables with the widget once
every retirement drains instead of at close(), and skip the downsample
failure fallback when the model is already closed.
@github-actions

Copy link
Copy Markdown

tradingview-lightweight docs preview (Available for 14 days)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A late partition fetch can reattach widget listeners after the model has closed.

1 open finding
What changed in this PR

Fixes server-side export leaks from partition-key tables in TradingView by= charts.

Changes:

  • Tracks and safely releases partition-key tables after subscriptions drain.
  • Handles asynchronous results arriving after closure.
  • Adds lifecycle regression tests.
File Description
TradingViewChartModel.ts Adds partition-table lifecycle management.
TradingViewChartModel.test.ts Tests closure and asynchronous race scenarios.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread plugins/tradingview-lightweight/src/js/src/TradingViewChartModel.ts
…during init

If close() runs during one of init()'s awaits, it has already done its
listener cleanup, so attaching widget listeners afterwards leaves them
attached for good.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The cleanup logic addresses the leak while preserving in-flight snapshots, with focused regression coverage for the relevant asynchronous paths.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@dsmmcken
dsmmcken marked this pull request as ready for review October 13, 2026 16:01
@dsmmcken
dsmmcken requested a review from jnumainville October 13, 2026 16:01
@github-actions

Copy link
Copy Markdown

tradingview-lightweight docs preview (Available for 14 days)

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