diff --git a/pkg/exporter/probe/tracekernel/tracekernel.go b/pkg/exporter/probe/tracekernel/tracekernel.go index dff3f280..544dcd75 100644 --- a/pkg/exporter/probe/tracekernel/tracekernel.go +++ b/pkg/exporter/probe/tracekernel/tracekernel.go @@ -120,9 +120,7 @@ type kernelLatencyProbe struct { metricsLock sync.RWMutex } -func (p *kernelLatencyProbe) stop(_ context.Context, probeType probe.Type) error { - p.lock.Lock() - defer p.lock.Unlock() +func (p *kernelLatencyProbe) stopLocked(probeType probe.Type) error { if p.refcnt[probeType] == 0 { return fmt.Errorf("probe %s never start", probeType) } @@ -141,6 +139,12 @@ func (p *kernelLatencyProbe) stop(_ context.Context, probeType probe.Type) error return nil } +func (p *kernelLatencyProbe) stop(_ context.Context, probeType probe.Type) error { + p.lock.Lock() + defer p.lock.Unlock() + return p.stopLocked(probeType) +} + func (p *kernelLatencyProbe) cleanup() error { if p.perfReader != nil { p.perfReader.Close() @@ -182,6 +186,7 @@ func (p *kernelLatencyProbe) start(ctx context.Context, probeType probe.Type) (e p.refcnt[probeType]++ if p.totalReferenceCountLocked() == 1 { if err = p.loadAndAttachBPF(); err != nil { + p.refcnt[probeType]-- log.Errorf("%s failed load and attach bpf, err: %v", probeName, err) _ = p.cleanup() return fmt.Errorf("%s failed load bpf: %w", probeName, err) @@ -192,7 +197,7 @@ func (p *kernelLatencyProbe) start(ctx context.Context, probeType probe.Type) (e p.perfReader, err = perf.NewReader(p.objs.bpfMaps.InspKlatencyEvent, int(unsafe.Sizeof(bpfInspKlEventT{}))) if err != nil { log.Errorf("%s failed create perf reader, err: %v", probeName, err) - _ = p.stop(ctx, probeType) + _ = p.stopLocked(probeType) return fmt.Errorf("%s failed create bpf reader: %w", probeName, err) }