Fix memory leak: clean up stale/failed items from extract map#624
Open
mprachar wants to merge 1 commit intoUnpackerr:mainfrom
Open
Fix memory leak: clean up stale/failed items from extract map#624mprachar wants to merge 1 commit intoUnpackerr:mainfrom
mprachar wants to merge 1 commit intoUnpackerr:mainfrom
Conversation
Three pre-existing leak paths cause unbounded memory growth over days: 1. EXTRACTFAILED items with exhausted retries have no matching case in checkExtractDone() — they stay in u.Map forever holding xtractr.Response 2. EXTRACTFAILED folder items with exhausted retries and positive DeleteAfter match no case in checkFolderStats() — stuck in both maps forever 3. Items stuck at EXTRACTED/EXTRACTING/QUEUED (e.g. Starr app never imports) have no TTL — they hold xtractr.Response indefinitely Fixes: - Add retries-exhausted cleanup case in handlers.go and folder.go - Add 24-hour stale item safety net for intermediate states - Add opt-in pprof debug endpoints (webserver.pprof config) for profiling Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Context
Note: These fixes were originally thought to be the root cause of observed memory growth (3.5GB after 4 days). After deploying with pprof enabled, heap profiling revealed the actual cause is in
golift.io/xtractrcue.go— the FLAC encoder loads entire files into memory during CUE splitting (writeTrackFLAC→flac.(*Encoder).WriteFrame, 121K allocations / 1.8GB).These changes are still valuable as defensive improvements — they prevent unbounded map growth from stuck items — but they do not address the primary memory issue.
Changes
handlers.goEXTRACTFAILEDretries-exhausted →DELETEDcasehandlers.goEXTRACTED/EXTRACTING/QUEUEDfolder.goEXTRACTFAILEDretries-exhausted → cleanup from both mapswebserver.goPprofconfig field (default: false) and/debug/pprof/*endpointsstart.gostaleItemTimeoutconstant (24 hours)What these fix
Three code paths allow items to stay in
u.Mapindefinitely:EXTRACTFAILEDwith exhausted retries — no switch case matched incheckExtractDone()EXTRACTFAILEDfolder items — same gap incheckFolderStats()EXTRACTED/EXTRACTING/QUEUEDhad no maximum ageEach stuck item holds a
*xtractr.Responsewith file lists. Over time this causes gradual map growth, though the primary memory consumer is the xtractr FLAC encoder (separate issue).Test plan
go build ./...passesgo test ./...passesgo vet ./...passes🤖 Generated with Claude Code