Fix memory leaks and race conditions causing OOM shutdowns#24
Open
TheMarstonConnell wants to merge 5 commits into
Open
Fix memory leaks and race conditions causing OOM shutdowns#24TheMarstonConnell wants to merge 5 commits into
TheMarstonConnell wants to merge 5 commits into
Conversation
…utdowns - Add mutex to Queue struct to prevent data races on messages/stopped/running - Cap broadcast retries at 10 and queue size at 500 to prevent unbounded growth - Stop passing *gin.Context to background goroutines (causes leaks after handler returns) - Replace http.DefaultClient mutation with package-level clients with timeouts - Add DB connection pool limits (25 open, 5 idle, 5min lifetime) - Fix storage purchaser goroutine silently exiting on query error - Fix GetUsage returning nil error when no customer found - Use COALESCE in SUM queries to handle empty tables Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Queue tests (17 tests): - NewQueue initialization, Stop, Size, TooBusy threshold - Post backpressure: rejects when full (500), accepts when not full - Post blocks until released, returns error from MsgHolder - Concurrent Post/Size/TooBusy/Stop with race detector - popAndPost returns on empty queue, batches at most 20 messages - Listen goroutine exits when stopped GetUsage tests (5 tests): - Returns error (not nil) when no customer found - Success path with correct byte calculations - Handles empty files table via COALESCE - Handles missing subscription - Handles customer query failure Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ents, and uploads Tests cover auth checks, SQL query correctness, pagination wiring, error handling, and edge cases (empty results, not-found, DB errors) using httptest + go-sqlmock. Co-Authored-By: Claude Opus 4.6 <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
sync.Mutexto protectmessages,stopped, andrunningfields accessed from multiple goroutines without synchronizationpopAndPost()retried forever if blockchain was unreachable — capped at 10 retries, then releases waiting goroutines with errorPost()now rejects new messages when queue exceeds 500, providing backpressure instead of growing until OOM*gin.Context:ProcessFile,PostFile, andUpdateCollectionno longer receive*gin.Contextin background goroutines — dependencies are extracted before goroutine launchhttp.DefaultClientmutation: Replaced with package-level clients (uploadClient,cloneClient) with 120s timeoutshttp.Get()calls replaced with context-aware requests usingcloneClientMaxOpenConns(25),MaxIdleConns(5),ConnMaxLifetime(5min)returntocontinueon query error + addedCOALESCEfor empty tablesGetUsagereturningnil, nil: Now returns proper error when no customer foundTest plan
go build ./...passes (verified)go vet ./...passes (verified)🤖 Generated with Claude Code