Skip to content

Fix HLS cleanup, investigation playback, backup I/O, and ONVIF handling - #606

Open
matteius wants to merge 6 commits into
mainfrom
fix/backlog-recording-reliability
Open

Fix HLS cleanup, investigation playback, backup I/O, and ONVIF handling#606
matteius wants to merge 6 commits into
mainfrom
fix/backlog-recording-reliability

Conversation

@matteius

Copy link
Copy Markdown
Contributor

HLS cleanup changes process-wide signal dispositions, native investigation play/pause leaves shared controls out of sync, and backup verification repeatedly evicts pages it needs to reread. This PR fixes those behaviors and hardens ONVIF subscription URL handling and empty-response diagnostics.

  • Remove HLS alarms, temporary SIGALRM/SIGSEGV handlers, and the freed-memory probe. Preserve FFmpeg-owned codec metadata until input closure, fixing the leak exposed by concurrent stream lifecycle tests.
  • Synchronize native investigation play/pause with shared playback state while allowing the shared clock to continue through media reloads and clip boundaries.
  • Retain reclaimable file cache during full backup integrity verification; keep copy-batch cache release, final eviction, abort checks, and deadlines. Schedule the next interval from completion and defer failed retries without counting them as successful backups.
  • Parse the ONVIF destination from SubscriptionReference, support XML prefixes and escaped query strings, escape wsa:To, reject empty HTTP 200 responses, disable curl signal use, and log the action, curl/HTTP codes, and elapsed time.
  • Add a repeatable RTSP/ONVIF harness that checks actual pre-trigger footage, plus a backup I/O benchmark and investigation notes.

Validation: frontend production build; six targeted C suites (backup, ONVIF, packet buffer, HLS cleanup, MP4 timestamps, and system API); two investigation browser tests; and two existing sub-stream/fullscreen browser tests passed. Concurrent HLS shutdown/restart passed with AddressSanitizer and LeakSanitizer enabled. The synthetic ONVIF test produced a decodable 31.4-second MP4 containing red footage before the trigger and blue footage afterward, with approximately eight seconds of pre-buffer.

The repeatable 82 MB audit fixture read 178 MB with repeated eviction versus 82 MB without it; both integrity checks passed. Verification can use more reclaimable OS page cache until completion. This small local benchmark does not predict production backup duration.

Related: #600, #603, #580, #604, #568, #494, #579. The affected cameras are unavailable, so the Tapo report, camera-specific pre-buffer behavior, and connection instability remain unconfirmed. Persistent SQLite I/O errors still need the extended error code and remain separate from backup performance. The reported HLS deadlock did not reproduce. Existing main-stream reuse behavior was verified without changing stream selection.

Detailed results and reproduction commands: backlog reliability notes.

Comment thread tests/integration/synthetic-onvif-prebuffer.py Fixed
Comment thread tests/integration/synthetic-onvif-prebuffer.py Fixed

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

HLS teardown still accesses potentially freed context memory, and the HLS test fixture does not clean up the global shutdown coordinator.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes HLS cleanup, investigation playback synchronization, backup verification behavior, and ONVIF subscription handling.

Changes:

  • Updates HLS lifecycle cleanup and FFmpeg metadata ownership.
  • Synchronizes investigation playback controls and validates pre-buffering.
  • Improves backup scheduling/cache handling and ONVIF parsing diagnostics.
File summaries
File Description
web/js/components/preact/investigation/InvestigationView.jsx Synchronizes native playback controls.
tests/unit/test_hls_cleanup.c Adds concurrent HLS lifecycle coverage.
tests/unit/test_detection_system_onvif.c Adds ONVIF regression tests.
tests/unit/CMakeLists.txt Registers HLS cleanup tests.
tests/integration/synthetic-onvif-prebuffer.py Adds repeatable pre-buffer validation.
tests/integration/specs/investigation.ui.spec.ts Tests investigation playback synchronization.
tests/database/db_backup_test.c Tests backup retry behavior.
tests/database/benchmark_backup_verification.py Benchmarks verification I/O.
src/video/onvif_detection.c Hardens ONVIF parsing and diagnostics.
src/video/hls/hls_unified_thread.c Updates HLS lifecycle cleanup.
src/video/hls_writer.c Removes alarm-based cleanup handling.
src/video/ffmpeg_utils.c Preserves FFmpeg-owned metadata.
src/database/db_core.c Adjusts backup scheduling and success tracking.
src/database/db_backup.c Improves verification cache handling.
src/core/main.c Updates shutdown signal handling.
src/core/daemon.c Updates daemon signal handling comments.
docs/internal/BACKLOG_RELIABILITY_2026-09-12.md Documents validation and findings.
Review details

Suppressed comments (1)

tests/unit/test_hls_cleanup.c:85

  • setUp reinitializes the process-global shutdown coordinator for every test, but tearDown never calls shutdown_coordinator_cleanup(). After the first test, the next init_shutdown_coordinator() overwrites live pthread mutex/condition-variable objects with memset, which is undefined behavior and leaks their resources. Destroy the coordinator in tearDown before the next test starts.
void tearDown(void) {
    cleanup_all_hls_writers();
    remove_test_files(test_dir);
}
  • Files reviewed: 17/17 changed files
  • Comments generated: 2
  • Review effort level: Lite

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


| Issue | Implemented or verified locally | Remaining evidence |
| --- | --- | --- |
| [#600](https://github.com/opensensor/lightNVR/issues/600) | Removed HLS `alarm()` calls and temporary SIGALRM/SIGSEGV dispositions; removed the freed-memory probe. Concurrent writer closure and full stream shutdown/restart pass. Fixed a codec metadata leak exposed by the lifecycle test. | The reported connection to a particular deadlock remains unproven. The system API suite completes. These tests do not establish freedom from every existing HLS context lifetime race. |
Comment on lines +229 to 230
// Never probe memory through a pointer that may already have been freed.
return result;
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