ipfs/kubo · error

generating profile data for %q: %w

Error message

generating profile data for %q: %w

What it means

In profile.WriteProfiles, each named profile is collected concurrently by calling c.collectFunc(ctx, p.opts, &b), which runs a pprof/realtime collector and writes the profile bytes into a buffer. If any collector returns an error, it is wrapped with the profile's archive file name (fName) and sent over the results channel so runProfile aborts with it. It means one specific profile (e.g. heap, goroutine, mutex) could not be generated, not that the whole archive machinery failed.

Source

Thrown at profile/profile.go:168

	results := make(chan profileResult, len(p.opts.Collectors))
	wg := sync.WaitGroup{}
	for _, c := range collectorsToRun {
		if !c.enabledFunc(p.opts) {
			continue
		}

		fName := c.outputFileName()

		wg.Add(1)
		go func(c collector) {
			defer wg.Done()
			logger.Infow("collecting profile", "File", fName)
			defer logger.Infow("profile done", "File", fName)
			b := bytes.Buffer{}
			err := c.collectFunc(ctx, p.opts, &b)
			if err != nil {
				select {
				case results <- profileResult{err: fmt.Errorf("generating profile data for %q: %w", fName, err)}:
				case <-ctx.Done():
					return
				}
			}
			select {
			case results <- profileResult{buf: &b, fName: fName}:
			case <-ctx.Done():
			}
		}(c)
	}
	go func() {
		wg.Wait()
		close(results)
	}()

	for res := range results {
		if res.err != nil {
			return res.err

View on GitHub (pinned to 329838acdf)

Solutions

  1. Read the wrapped inner error and the quoted fName to identify which collector failed and why
  2. Check the Options struct passed to WriteProfiles: profile fractions must be >= 0 and requested profiles must exist at runtime
  3. Ensure the ctx passed to WriteProfiles is alive for the whole collection duration
  4. Disable or fix the failing collector in the profile list before retrying

Example fix

// before
collectFunc: func(ctx context.Context, opts Options, w io.Writer) error {
    return pprof.Lookup(opts.ProfileName).WriteTo(w, opts.Debug) // panics/errs on unknown name
}
// after
collectFunc: func(ctx context.Context, opts Options, w io.Writer) error {
    p := pprof.Lookup(opts.ProfileName)
    if p == nil {
        return fmt.Errorf("unknown profile %q", opts.ProfileName)
    }
    return p.WriteTo(w, opts.Debug)
}
Defensive patterns

Strategy: try-catch

Validate before calling

if ctx.Err() != nil {
    return fmt.Errorf("cannot collect profiles: %w", ctx.Err())
}
for _, c := range collectors {
    if err := c.Validate(opts); err != nil {
        return fmt.Errorf("invalid profile options: %w", err)
    }
}

Try / catch

err := WriteProfiles(ctx, p)
if err != nil {
    var fname string
    if n, serr := fmt.Sscanf(err.Error(), "generating profile data for %q", &fname); serr == nil && n == 1 {
        log.Printf("profile %s failed: %v", fname, errors.Unwrap(err))
    }
    return err
}

Prevention

When it happens

Trigger: Calling WriteProfiles when a collector fails: e.g. opts.RequestGoroutineStackDump rejected, runtime/pprof lookup of an unknown profile name, an unsupported Options value (invalid MutexProfileFraction or ProfileFraction), or the passed ctx already cancelled/expired before collection starts.

Common situations: Diagnostics bundles (ipfs profile dumps) taken with a bad options struct; profile collection during shutdown when ctx is already done; custom collectFunc plugins that return errors on platforms lacking runtime support (e.g. some sandboxed/container runtimes).

Related errors


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/8851576ffdf78f3d. Report an issue: GitHub.