Skip to content

Commit 1d13991

Browse files
lmbti-mo
authored andcommitted
link: do not attempt to clean up perf event and tracefs event in order
Switching to runtime.AddCleanup means that cleanups may be batched and may run concurrently. Since both the perf event and the tracefs event will have a cleanup attached it's not possible to guarantee an ordering. Drop the code which tries to clean up in order when the object is leaked without calling Close(). Signed-off-by: Lorenz Bauer <[email protected]>
1 parent d1a69ef commit 1d13991

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

link/perf_event.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"fmt"
88
"os"
9-
"runtime"
109
"unsafe"
1110

1211
"github.com/cilium/ebpf"
@@ -61,15 +60,11 @@ type perfEvent struct {
6160

6261
func newPerfEvent(fd *sys.FD, event *tracefs.Event) *perfEvent {
6362
pe := &perfEvent{event, fd}
64-
// Both event and fd have their own finalizer, but we want to
65-
// guarantee that they are closed in a certain order.
66-
runtime.SetFinalizer(pe, (*perfEvent).Close)
6763
return pe
6864
}
6965

7066
func (pe *perfEvent) Close() error {
71-
runtime.SetFinalizer(pe, nil)
72-
67+
// We close the perf event before attempting to remove the tracefs event.
7368
if err := pe.fd.Close(); err != nil {
7469
return fmt.Errorf("closing perf event fd: %w", err)
7570
}

0 commit comments

Comments
 (0)