Skip to content

Unbounded memory growth when playing a remote Blu-ray ISO over HTTP #243

Closed

Description

@bitxeno

What happened?

I called engine.load() on a remote Blu-ray ISO (~59 GB, served over HTTP with byte-range support). Playback works, but process memory grows continuously and rapidly for the entire session: malloc in-use size climbs at roughly 30 MB/s (~6 GB after 150 s). RSS looks deceptively flat because the leaked pages are never touched again and get moved into the macOS compressor (vmCmp climbs steadily in the memprobe lines below). Left running, the process is eventually jetsammed.

Steps to reproduce

  1. Serve a Blu-ray ISO from any HTTP server with range-request support
  2. engine.load(url:) on the ISO URL — the engine recognizes the BDMV and routes it through DiscReader / HTTPDiscIOReader (the pull path via CustomIOReaderBridge).
  3. Let it play and watch the [AetherEngine] memprobe lines: mallocMB and vmCmp grow linearly (~800–900 MB per 30 s).

AetherEngine version or commit SHA

5.28.0

Host app

Custom / my own integration

Platform

macOS

OS version

macOS 15.7.7

Device / chip

Mac mini m4

Playback path

Native AVPlayer

Source media (for playback bugs)

Blu-ray ISO (UDF/BDMV), ~59.11 GB. Selected title: AV1 (av01), 3840x2160, HDR10, 23.976 fps, 13 audio tracks, 13 PGS subtitle tracks.

Error codes / log lines

[AetherEngine] memprobe t=30s rss=1991MB vmInt=1629MB vmExt=240MB vmCmp=456MB vmIOS=0MB physFP=1481MB
   mallocBlocks=1042068 mallocMB=2476 avioFetchedMB=0 cacheCount=20 cacheMB=304 packetsWritten=1910 audioFifo=0
   abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=304 muxCuts=20 srvConns=1 srvBytesMB=150 srvSfMB=122 pktAlive=3
   pktTotal=44073 subCues=2 prefetch=park prefetchLead=59.8s prefetchHarvested=14434 prefetchTbFallback=0 swFrames=0
   audioTracks=13 subTracks=13 subActive=true avBufAhead=5.8s avBufBehind=31.9s frameAhead=0.00s prodShift=2.69s
   hostShift=2.69s seams=1
[AetherEngine] memprobe t=60s rss=1608MB vmInt=1368MB vmExt=240MB vmCmp=1203MB vmIOS=0MB physFP=1935MB
   mallocBlocks=1297122 mallocMB=3442 avioFetchedMB=0 cacheCount=27 cacheMB=447 packetsWritten=2643 audioFifo=0
   abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=447 muxCuts=27 srvConns=1 srvBytesMB=269 srvSfMB=241 pktAlive=2
   pktTotal=60998 subCues=2 prefetch=park prefetchLead=59.5s prefetchHarvested=20443 prefetchTbFallback=0 swFrames=0
   audioTracks=13 subTracks=13 subActive=true avBufAhead=7.8s avBufBehind=30.2s frameAhead=0.00s prodShift=2.69s
   hostShift=2.69s seams=1
[AetherEngine] memprobe t=90s rss=1605MB vmInt=1367MB vmExt=237MB vmCmp=1658MB vmIOS=0MB physFP=2422MB
   mallocBlocks=1552671 mallocMB=4311 avioFetchedMB=0 cacheCount=35 cacheMB=589 packetsWritten=3349 audioFifo=0
   abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=589 muxCuts=35 srvConns=1 srvBytesMB=407 srvSfMB=380 pktAlive=3
   pktTotal=78040 subCues=2 prefetch=park prefetchLead=59.8s prefetchHarvested=25490 prefetchTbFallback=0 swFrames=0
   audioTracks=13 subTracks=13 subActive=true avBufAhead=5.8s avBufBehind=32.2s frameAhead=0.00s prodShift=2.69s
   hostShift=2.69s seams=1
[AetherEngine] memprobe t=120s rss=1528MB vmInt=1357MB vmExt=171MB vmCmp=2065MB vmIOS=0MB physFP=2786MB
   mallocBlocks=1817452 mallocMB=5115 avioFetchedMB=0 cacheCount=43 cacheMB=711 packetsWritten=4117 audioFifo=0
   abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=711 muxCuts=43 srvConns=1 srvBytesMB=552 srvSfMB=524 pktAlive=3
   pktTotal=97247 subCues=2 prefetch=park prefetchLead=59.8s prefetchHarvested=31410 prefetchTbFallback=0 swFrames=0
   audioTracks=13 subTracks=13 subActive=true avBufAhead=7.7s avBufBehind=30.2s frameAhead=0.00s prodShift=2.69s
   hostShift=2.69s seams=1
[AetherEngine] memprobe t=150s rss=1293MB vmInt=1157MB vmExt=136MB vmCmp=2805MB vmIOS=0MB physFP=3295MB
   mallocBlocks=2098578 mallocMB=6081 avioFetchedMB=0 cacheCount=50 cacheMB=867 packetsWritten=4790 audioFifo=0
   abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=867 muxCuts=50 srvConns=1 srvBytesMB=679 srvSfMB=651 pktAlive=3
   pktTotal=111138 subCues=2 prefetch=park prefetchLead=59.8s prefetchHarvested=35786 prefetchTbFallback=0 swFrames=0
    audioTracks=13 subTracks=13 subActive=true avBufAhead=5.7s avBufBehind=32.2s frameAhead=0.00s prodShift=2.69s
   hostShift=2.69s seams=1

Anything else

Root cause analysis / fix suggestion

The leak is in HTTPDiscIOReader.rangeGet (Sources/AetherEngine/IO/HTTPDiscIOReader.swift). The disc path is pull-based: FFmpeg's read callback runs on the demux thread and synchronously performs each range request there (session.dataTask(with:) + semaphore wait). dataTask(with:) and the surrounding Foundation bridging produce autoreleased ObjC objects — including the task, which retains request/response buffers. The demux pump thread is a long-lived busy loop that never drains an autorelease pool, so every range fetch strands its objects for the lifetime of the session.

The arithmetic matches: three concurrent readers (main demuxer + subtitle side demuxer + 60 s forward-prefetch demuxer, each with an independent HTTPDiscIOReader fork) × ~8 MB adaptive chunks at a few requests/s ≈ 30 MB/s.

Suggested fix: wrap the body of rangeGet in autoreleasepool { ... } so each request's autoreleased objects are released as soon as the synchronous round-trip completes. This covers probeSize and fetchWithRetry too, since both go through rangeGet. Verified locally: with the wrapper, mallocMB/vmCmp stay flat during ISO playback.

Activity

  1. added
    bug
    on Jul 29, 2026
  2. added 2 commits that reference this issue on Jul 29, 2026
  3. superuser404notfound commented on Jul 29, 2026

    @superuser404notfound
    Owner

    Fixed in 5.28.2 (PR #245). Thanks for a report that arrived with the site, the mechanism and the fix already in it, and for reading the compressor behaviour correctly off the memprobe lines: rss staying flat while vmCmp and physFP climb is exactly what sends this class of leak unnoticed for a while.

    rangeGet now drains per request, which covers probeSize and every retry as suggested. Two things came out of verifying it.

    The local twin had the same defect. FileIOReader.read hands back an NSData-backed Data from FileHandle.read on that same never-draining thread, so a local disc image leaked one byte per byte played: 624 MB read in 32 KB chunks left 625 MB in use, and 0 MB with the pool. SMBIOReader copies out of a dispatch_data-backed body there too and got the same wrapper.

    A per-request URLSession is not a fix, which matters because the engine's older comments claimed it was. Measured against a local range origin, 480 MB fetched in 8 MB requests:

    variant malloc in use
    shared session, completion handler, no pool +968 MB
    session per request + invalidate, no pool +973 MB
    shared session, completion handler, pool per request 0 MB
    shared session, delegate-based delivery, no pool 0 MB

    So the retention was never inside URLSession's task pool, as the AVIOReader leak of 5.x had been recorded. The owner is the caller thread's pool in both cases, and delegate-based delivery worked there because it releases the body on the delegate queue, where the demux thread never sees it. Those comments are corrected.

    5.28.2 also adds discFetchedMB to the 30 s memprobe. The disc pull path had no byte counter at all (avioFetchedMB covers the AVIOReader path only), which is why this session reports every engine-tracked pool flat while three reader forks pull tens of MB/s. On a retest it gives the fetch rate directly, so the expectation is mallocMB and vmCmp flat while discFetchedMB keeps climbing at roughly the media rate times the number of active readers.

    Leaving this open for a retest on the same ISO. If anything still grows, the memprobe lines with discFetchedMB in them are the useful ones.

  4. bitxeno commented on Jul 29, 2026

    @bitxeno
    Author

    I retested, the memory growth is gone now.

    [AetherEngine] memprobe t=30s rss=1273MB vmInt=1022MB vmExt=241MB vmCmp=97MB vmIOS=0MB physFP=483MB mallocBlocks=1113614 mallocMB=527 avioFetchedMB=0 discFetchedMB=1355 cacheCount=19 cacheMB=328 packetsWritten=1852 audioFifo=512 abFifoKB=12 abSwrKB=0 abTotKB=12 muxBytesMB=328 muxCuts=19 srvConns=1 srvBytesMB=167 srvSfMB=143 pktAlive=2 pktTotal=50144 subCues=0 prefetch=park prefetchLead=59.8s prefetchHarvested=18288 prefetchTbFallback=0 prefetchYielded=0s swFrames=0 audioTracks=13 subTracks=13 subActive=true avBufAhead=8.0s avBufBehind=29.9s frameAhead=0.00s prodShift=1.96s hostShift=1.96s seams=1
    [AetherEngine] memprobe t=60s rss=1132MB vmInt=891MB vmExt=240MB vmCmp=236MB vmIOS=0MB physFP=492MB mallocBlocks=1382157 mallocMB=589 avioFetchedMB=0 discFetchedMB=1851 cacheCount=27 cacheMB=534 packetsWritten=2600 audioFifo=0 abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=534 muxCuts=27 srvConns=1 srvBytesMB=278 srvSfMB=253 pktAlive=4 pktTotal=65886 subCues=3 prefetch=read prefetchLead=56.0s prefetchHarvested=22605 prefetchTbFallback=0 prefetchYielded=2s swFrames=0 audioTracks=13 subTracks=13 subActive=true avBufAhead=5.9s avBufBehind=32.0s frameAhead=0.00s prodShift=1.96s hostShift=1.96s seams=1
    [AetherEngine] memprobe t=90s rss=1166MB vmInt=926MB vmExt=239MB vmCmp=306MB vmIOS=0MB physFP=596MB mallocBlocks=1622793 mallocMB=636 avioFetchedMB=0 discFetchedMB=2299 cacheCount=34 cacheMB=668 packetsWritten=3286 audioFifo=0 abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=668 muxCuts=34 srvConns=1 srvBytesMB=498 srvSfMB=474 pktAlive=2 pktTotal=74752 subCues=15 prefetch=yield prefetchLead=59.5s prefetchHarvested=23551 prefetchTbFallback=0 prefetchYielded=4s swFrames=0 audioTracks=13 subTracks=13 subActive=true avBufAhead=7.9s avBufBehind=30.0s frameAhead=0.00s prodShift=1.96s hostShift=1.96s seams=1
    [AetherEngine] memprobe t=120s rss=1171MB vmInt=933MB vmExt=237MB vmCmp=310MB vmIOS=0MB physFP=606MB mallocBlocks=1865110 mallocMB=619 avioFetchedMB=0 discFetchedMB=2771 cacheCount=42 cacheMB=846 packetsWritten=4039 audioFifo=0 abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=846 muxCuts=42 srvConns=1 srvBytesMB=622 srvSfMB=598 pktAlive=3 pktTotal=82917 subCues=26 prefetch=park prefetchLead=61.0s prefetchHarvested=24437 prefetchTbFallback=0 prefetchYielded=5s swFrames=0 audioTracks=13 subTracks=13 subActive=true avBufAhead=5.9s avBufBehind=32.1s frameAhead=0.00s prodShift=1.96s hostShift=1.96s seams=1
    [AetherEngine] memprobe t=150s rss=1165MB vmInt=927MB vmExt=237MB vmCmp=294MB vmIOS=0MB physFP=585MB mallocBlocks=2062366 mallocMB=637 avioFetchedMB=0 discFetchedMB=3123 cacheCount=49 cacheMB=979 packetsWritten=4749 audioFifo=1024 abFifoKB=24 abSwrKB=0 abTotKB=24 muxBytesMB=979 muxCuts=49 srvConns=1 srvBytesMB=795 srvSfMB=771 pktAlive=2 pktTotal=90698 subCues=35 prefetch=yield prefetchLead=58.3s prefetchHarvested=25292 prefetchTbFallback=0 prefetchYielded=6s swFrames=0 audioTracks=13 subTracks=13 subActive=true avBufAhead=7.9s avBufBehind=30.0s frameAhead=0.00s prodShift=1.96s hostShift=1.96s seams=1
    
  5. added a commit that references this issue on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions