Skip to content

Stop a streaming sound's decode thread when it's dropped - #166

Merged
tesselode merged 1 commit into
tesselode:mainfrom
VoltaSoftware:lot
Oct 28, 2026
Merged

tesselode merged 1 commit into
tesselode:mainfrom
VoltaSoftware:lot

Conversation

@jonatino

Copy link
Copy Markdown
Contributor

If a streaming sound gets dropped without being stopped, its decode thread never exits. It fills its buffer and then wakes every 1ms forever.

Two easy ways to hit it:

  • play() starts the thread in into_sound() before checking the sound limit, so every SoundLimitReached leaks one
  • dropping the AudioManager while streams are playing

We hit the first one on iOS: an audio interruption stopped the output, the track filled up, and we ended up with ~300 sleeping decode threads before running out of memory.

The fix marks the sound Stopped on drop so the scheduler ends. Added a test that fails without it.

The decode scheduler's thread only ends once the sound is stopped or reaches its end. A sound refused by the sound limit, or dropped with the audio manager while playing, is never stopped, so its thread waited on a full frame buffer forever, waking every millisecond. Each refused play leaked one thread.
@tesselode

Copy link
Copy Markdown
Owner

looks good, thank you!

@tesselode
tesselode merged commit f6d8b2c into tesselode:main Oct 28, 2026
24 checks passed
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