Skip to content

fix(lane): close WebIdHelper's observation lookups so they release DuckDB sessions - #60

Merged
1 commit merged into
ORNL:mainfrom
mjd948:fix/webid-lookup-session-leak
Nov 25, 2026
Merged

1 commit merged into
ORNL:mainfrom
mjd948:fix/webid-lookup-session-leak

Conversation

@mjd948

@mjd948 mjd948 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Problem

WebIdHelper finds the stored observation for each WebID and occupancy event with
store.selectKeys(filter).findFirst().get() and never closes the stream.

On the tiered PostGIS store, a query that reaches the cold (Parquet) tier holds a DuckDB admission
permit. The permit is released only by the stream's onClose (OscarTieredObsStore /
ParquetArchiveReader). The default duckDbMaximumConcurrentSessions is 2, so two leaked
lookups take every cold-tier session for good. From then on, every historical query fails after 30 s
with DuckDB session capacity is busy for operation cold-query after 30 seconds. The viewer's alarm
table shows "Events could not be loaded", and the video-retention scan fails too. Only a restart
clears it.

Seen on a 24/7 3.11.11 site with one RS-350 lane. Two WebID events whose phenomenon-time lookup
matched nothing ("Empty filter intersection", a NoSuchElementException from Optional.get())
leaked the two sessions 70 minutes apart:

  • each leak left a cold-query-<uuid> directory in duckdb-tmp, and their timestamps match the
    two errors to the second;
  • a thread dump showed no thread inside DuckDB, only waiters in AdmissionController.acquire.

#56 (in 3.11.14) re-attaches WebIdHelper when the RS-350 comes up late, so on more nodes the
helper is now running and able to leak.

Fix

Both lookups now use try-with-resources and findFirst().orElse(null). When nothing matches, the
helper logs a warning with the phenomenon time and returns. Before, it logged an error with a
stack trace.

Verification

  • sensorhub-system-lane tests: 68 passed.
  • Deployed on the affected site. After the restart no cold-query-* directories remain, the alarm
    table's query returns 200, a 7-day per-datastream query returns in 0.09 s, and WebID subscribes on
    the RS-350 lane.

Not changed here (worth a look)

Other observation-store reads in this repo don't close their stream either, so they could leak the
same way when they reach the cold tier:

  • StatisticsOutput.getLatestObservationIdWithinScope / getLastObservation
  • OccupancyDataRecorder (select(filter).collect(...))
  • RS-350 MessageHandler (latest occupancy key)
  • DatabasePurger.getOccupancyWindowsByLane
  • TrainingSandboxManager (several)

None of them leaked on the site above, possibly because a fully consumed cursor, or a
latest-result query, never holds a cold session. I kept this PR to the one confirmed leak. I can
follow up with the rest if you'd like them closed too.

🤖 Generated with Claude Code

…query slot

An unclosed selectKeys() stream that reached the cold tier kept one of the node's two DuckDB sessions forever. Two empty WebID matches on an RS-350 lane were enough to block every historical query (alarm table: 'Events could not be loaded').

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tyronechrisharris tyronechrisharris closed this pull request by merging all changes into ORNL:main in eed1679 Nov 25, 2026
@tyronechrisharris

Copy link
Copy Markdown
Collaborator

Thank you @mjd948 for tracking down this critical 2-session DuckDB pool leak!

c766f733 has been integrated directly onto main via ORNL/osh-oakridge-modules#61 for OSCAR v3.11.15, alongside three structural companions so this class of session exhaustion cannot recur elsewhere in the stack:

  1. limit = 1 pushdown on WebIdHelper lookups (#61): Added .withLimit(1) to both ObsFilter.Builder queries in processWebIdEvent and processOccupancyEvent (verified by WebIdHelperStreamCloseTest). Previously limit defaulted to Long.MAX_VALUE, which routed single-generation lookups through ParquetArchiveReader.stream(...)'s eager openRowStream path without ClosingLimitIterator auto-close.
  2. Full repository audit of unclosed IObsStore.select* / ISystemDescStore.select* streams (#61): Wrapped all remaining unclosed store streams across DatabasePurger, OccupancyDataRecorder, RS-350 MessageHandler, StatisticsOutput, OSCARServiceModule.refreshSiteDiagram, TrainingSandboxManager (also removing a duplicate no-op scan), and LaneSystem in try-with-resources, and codified the rule in AGENTS.md.
  3. Lazy cold-tier & overlay cursor initialization in OscarTieredObsStore (ORNL/osh-addons#20): Wrapped cold Parquet (streamColdBases*) and JDBC overlay (streamOverlays) streams in OscarTieredObsStore.lazyStream(...) and deferred upstream Iterator acquisition inside MergingIterator, MutationFilteringIterator, and ClosingLimitIterator (TestLazyTieredStreamLifecycle) so constructing selectEntries / selectKeys never acquires a DuckDbResourcePolicy.Session permit before terminal iteration actually reaches the cold tier.

mjd948 pushed a commit to mjd948/osh-oakridge-modules that referenced this pull request Nov 25, 2026
mjd948 added a commit to mjd948/osh-oakridge-modules that referenced this pull request Nov 25, 2026
ORNL squash-merged our session, RS-350, lane-recovery and WebID fixes
(ORNL#54, ORNL#55, ORNL#56, ORNL#60) plus their own follow-ups (ORNL#61), so their side was
taken in every conflict except two:

- LaneSystem keeps our Mobile Detector design (the occupancy process
  member is reused across restarts and covers D5 walkers); ORNL's
  "detector already started" start-up is kept for a newly created
  process, for RS-350 and D5 alike. EML re-attach follows ORNL.
- Rs350OccupancyProcessModule takes ORNL's version: its event-bus
  restart handler (where our orphan guard lived) is gone upstream.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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