Skip to content

fix: improve IPTV playlist concurrency safety and XMLTV parsing relia…#316

Open
saidai-bhuvanesh wants to merge 1 commit into
ProdigyV21:mainfrom
saidai-bhuvanesh:fix/iptv-epg-reliability-optimization
Open

fix: improve IPTV playlist concurrency safety and XMLTV parsing relia…#316
saidai-bhuvanesh wants to merge 1 commit into
ProdigyV21:mainfrom
saidai-bhuvanesh:fix/iptv-epg-reliability-optimization

Conversation

@saidai-bhuvanesh
Copy link
Copy Markdown

Overview

This Pull Request introduces critical performance and reliability improvements to the IPTV playlist loading and EPG XMLTV parsing engine in ARVIO. The changes address a silent crash condition during concurrent playlist loads and a complete bypass of backslash escape sanitization during EPG parsing.


Key Improvements

1. Concurrency Fix for Playlist Loading

  • Issue: When multiple playlists are configured, they are fetched concurrently using Kotlin coroutines. The results are aggregated into a Collections.synchronizedList. As each playlist finished, runCatching { onChannelsReady(aggregatedChannels.toList()) } copied the list. However, iterating on a synchronized list is not thread-safe and threw a ConcurrentModificationException when another thread added channels concurrently. This silenced the callback and prevented the UI from receiving channel updates.
  • Fix: Wrapped the .toList() copy operation in an explicit synchronized(aggregatedChannels) block in IptvRepository.kt.

2. Optimized Bulk Sanitization for EPG XMLTV Files

  • Issue: BackslashEscapeSanitizingInputStream (designed to filter JSON-style backslashes to prevent XML parser crashes) only overrode the single-byte read(). Because XML Pull/SAX parsers read in blocks, this filter was completely bypassed, causing crashes on malformed feeds.
  • Fix: Fully implemented read(b: ByteArray, off: Int, len: Int) to perform in-place sanitization directly on the byte buffer in a single pass. A lookahead mechanism handles split backslash boundaries cleanly.

3. Unit Test Verification

  • Created a comprehensive test suite in IptvRepositoryOptimizationTest.kt verifying:
    • Bulk block-read sanitization.
    • Byte-by-byte sanitization.
    • Escape sequences split across chunk boundaries.
    • Trailing backslashes at end-of-stream.
    • Stress testing concurrent additions and list copying to guarantee thread safety.

Verification & Test Results

Both main build variants compile successfully, and the entire test suite passes without regressions:

  • PlayDebug compile: BUILD SUCCESSFUL (42 tasks executed/up-to-date)
  • SideloadDebug compile: BUILD SUCCESSFUL (42 tasks executed/up-to-date)
  • PlayDebug unit tests: BUILD SUCCESSFUL (all tests passed, including the new optimization test suite)

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.

1 participant