fix: guard against goroutine leaks, url injection, and missing timeouts#11
Merged
Merged
Conversation
- core/sync/presence.go: use context.WithTimeout(10s) for all Presence() calls to prevent goroutine leaks on network hang - core/sync/sync.go: url.PathEscape user input in UserByName to prevent path corruption with special characters - core/mitm/server.go: replace http.DefaultClient with gatewayClient (5min timeout) in intercept path, matching the passthroughClient pattern - core/sync/items.go + sync.go: O(1) dedup lookup maps for full-sync pull to avoid O(n^2) store scans at scale - server/handlers/api_debug.go: serialize proc access with mutex to prevent data race in concurrent Percent() calls
4 tasks
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
Multiple hardening fixes found during codebase audit.
Changes
Goroutine leak prevention
core/sync/presence.go— AllPresence()calls now usecontext.WithTimeout(10s)instead of barecontext.Background(). Previously a network hang in the presence heartbeat would leak goroutines indefinitely.URL path injection
core/sync/sync.go—UserByName()now escapes the username withurl.PathEscape()before appending to the URL path. Special characters in usernames (/,?,#) could corrupt the request path.Missing HTTP client timeout
core/mitm/server.go— Replacedhttp.DefaultClient(no timeout) with a dedicatedgatewayClient(5min timeout) in the intercept path, matching the existingpassthroughClientpattern.Full-sync dedup optimization
core/sync/items.go+core/sync/sync.go— Pre-built O(1) dedup lookup maps for full-sync pulls to avoid scanning the entire store per item (O(n²) at 1300+ accounts).Data race fix
server/handlers/api_debug.go— Addedsync.Mutexto serializeproc.Percent()andproc.MemoryInfo()calls. Previously concurrent polling from multiple browser tabs caused a data race producing wildly inflatedcpu_percentvalues.Test plan
go build ./...passesgo test ./core/sync/... ./core/mitm/... ./server/handlers/...passesgo test -race -run TestDebugConcurrentAccess ./server/handlers/...passes (no data race)