Skip to content

Conversation

@maheshbhatiya73
Copy link

Summary

perfEventLink.Close() previously returned early if closing the link FD failed,
skipping cleanup of the underlying perf event (pl.pe). This caused:

  • Perf event file descriptor leaks
  • Stale tracefs events
  • Potential resource exhaustion in long-running programs

Changes

This patch ensures that both resources are always closed, collecting all
errors using Go 1.20+ errors.Join:

func (pl *perfEventLink) Close() error {
    var errs []error
    if err := pl.fd.Close(); err != nil {
        errs = append(errs, fmt.Errorf("perf link close: %w", err))
    }
    if pl.pe != nil {
        if err := pl.pe.Close(); err != nil {
            errs = append(errs, fmt.Errorf("perf event close: %w", err))
        }
    }
    return errors.Join(errs...)
}

@lmb
Copy link
Collaborator

lmb commented Oct 22, 2025

Couple of questions:

  1. Have you seen this in problem in production?
  2. Did you make this PR using an AI coding tool?

@maheshbhatiya73 maheshbhatiya73 closed this by deleting the head repository Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants