feat: add goroutine-leak collector to 'ipfs diag profile' - #11406
Open
ecgang wants to merge 1 commit into
Open
Conversation
Collect Go's goroutineleak profile into goroutineleak.pprof when the binary was built with GOEXPERIMENT=goroutineleakprofile (a Go 1.26 experiment, expected to be enabled by default in Go 1.27). The collector is opt-in (not part of the default set) because collecting the profile triggers a goroutine-leak-detection GC cycle. Requesting it on a build without the experiment returns a clear error; availability is validated before any collector starts, so a mixed request fails up front rather than leaving a partially written archive. The profile is also served at /debug/pprof/goroutineleak via the existing pprof mux with no route changes. Closes ipfs#11191 Co-Authored-By: Claude Fable 5 <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.
Adds an opt-in
goroutine-leakcollector toipfs diag profile, backed by Go 1.26's experimental goroutine leak profiler (GOEXPERIMENT=goroutineleakprofile).What
goroutine-leakcollector inprofile/profile.gothat writesgoroutineleak.pprof(proto format, like the other pprof-backed collectors).goroutineleak profile is not available in this build (requires GOEXPERIMENT=goroutineleakprofile). Availability is validated synchronously, after name validation and before any collector starts, so a mixed request cannot leave a partially written archive, and theunknown collectorerror deterministically wins over the availability error across build variants./debug/pprof/goroutineleakneeds no route changes: the daemon mountsnet/http/pprof's handlers, which serve any registered runtime profile by name. Documented indocs/debug-guide.md.Design decisions (flagging for review)
ipfs diag profilerun the moment kubo builds move to a toolchain with the experiment enabled by default (expected in Go 1.27). That seemed like a decision a maintainer should make deliberately, so the collector is explicit-request only for now; promoting it to the default set later is a two-line change. Happy to flip it in this PR if you would rather have it on by default.goroutine-leakfollows the issue text; renaming togoroutines-leakfor symmetry with the existinggoroutines-*collectors is a one-liner if preferred.Tests
TestProfilercovers the gating in the standard suite:goroutine-leakjoins the collector list and the expected archive contents only when the profile is available, so the same assertions run under both build modes (the exact-file-count check proves absence on standard builds).TestGoroutineLeakProfileuses a mixed request (version+goroutine-leak): on standard builds it asserts the up-front error and that zero archive entries were written; on experiment builds it asserts both files are present andgoroutineleak.pprofis valid gzip-compressed proto.TestUnknownCollectorBeatsAvailabilitypins the validation order across build variants.go test ./profile/...green with and withoutGOEXPERIMENT=goroutineleakprofile;test/sharness/t0152-profile.shpasses all 26;TestCommandDocsWidthgreen; exercised end-to-end against a live daemon in both build modes (default run unchanged; explicit request collects on experiment builds and errors on standard builds;/debug/pprof/goroutineleakreturns 200 with gzip proto on experiment builds).Notes
GOEXPERIMENT, so the experiment-enabled halves of these tests do not run in CI today. If you want that coverage, I can add a small experiment-enabledgo test ./profile/...job in a follow-up; I did not touch.github/here per AGENTS.md.unknown collectoron master today), the CLI leaves an empty zip skeleton at the-opath because the output file is created before collection starts. Can address separately if worth fixing.References
ipfs diag profile#11191🤖 Generated with Claude Code