Fix memory leaks in long-running Docker container streams#12
Closed
Fix memory leaks in long-running Docker container streams#12
Conversation
Co-authored-by: Zozman <1192364+Zozman@users.noreply.github.com>
Co-authored-by: Zozman <1192364+Zozman@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] There seems to be a memory leak when running this repo as a docker container as there is an increase in memory usage if run for several days. Diagnose what might be the cause and propose a solution.
Fix memory leaks in long-running Docker container streams
Aug 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The stream-webpage-container was experiencing memory leaks when running continuously for several days. Memory usage would gradually increase over time, eventually causing performance degradation or container crashes in long-running deployments.
Root Cause Analysis
Investigation revealed several sources of memory leaks:
Process.Kill()but child processes weren't properly terminated, leading to zombie process accumulationSolution
This PR implements comprehensive memory leak fixes:
Enhanced Process Management
Setpgid: trueto enable complete process tree cleanupChrome Browser Resource Management
cleanupChromeProcesses()function kills remaining Chrome processesmax_old_space_size=512andmemory-pressure-offMemory Monitoring and Management
runtime.GC()calls before stream starts and after cleanuplogMemoryStats()function tracks heap usage, GC cycles, and system memoryGOMEMLIMIT="512MiB"to constrain Go memory usageStartup Optimizations
Testing
Added comprehensive tests:
TestCleanupChromeProcesses()- Validates Chrome process cleanupTestStopStreamWithProcessGroup()- Tests process group terminationExpected Impact
These changes should eliminate memory leaks for long-running containers by ensuring:
The container should now be suitable for multi-day continuous operation without memory accumulation.
Breaking Changes
None - all changes are backward compatible and don't affect the API or configuration.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
id.twitch.tv/tmp/go-build889050422/b343/twitch.test -test.testlogfile=/tmp/go-build889050422/b343/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true(dns block)If you need me to access, download, or install something from one of these locations, you can either:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.