Skip to content

Conversation

lmb
Copy link
Collaborator

@lmb lmb commented Apr 23, 2024

The perf reader was written before we had the sys.FD abstraction and therefore still uses plain int to keep track of fds. This means we don't get leak tracking during CI. It also relies on a subtle interaction between defer and named return values which is easy to break by accidentally shadowing err:

func ... (err error) {
    poller, err := poller.New(...)

    defer func() {
        if err != nil {} // Refers to the second err
    }()
}

Rework the code to use sys.FD and the closeOnError idiom used elsewhere in the library.

The perf reader was written before we had the sys.FD abstraction
and therefore still uses plain int to keep track of fds. This means
we don't get leak tracking during CI. It also relies on a subtle
interaction between defer and named return values which is easy to
break by accidentally shadowing err:

    func ... (err error) {
        poller, err := poller.New(...)

        defer func() {
            if err != nil {} // Refers to the second err
        }()
    }

Rework the code to use sys.FD and the closeOnError idiom used
elsewhere in the library.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
@lmb lmb requested a review from florianl as a code owner April 23, 2024 11:14
@lmb
Copy link
Collaborator Author

lmb commented Apr 23, 2024

@florianl your intuition was right that the error handling path in the perf reader is wonky. It's really old code by now, I think this should be better.

Copy link
Contributor

@florianl florianl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the cleanup! I think it is easier now to follow.

@lmb lmb merged commit 68770ff into cilium:main Apr 23, 2024
@lmb lmb deleted the perf-cleanup branch April 23, 2024 17:16
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