diff --git a/pkg/plugin/packetparser/packetparser_linux.go b/pkg/plugin/packetparser/packetparser_linux.go index fb54c8bb5e..c11ef9cef9 100644 --- a/pkg/plugin/packetparser/packetparser_linux.go +++ b/pkg/plugin/packetparser/packetparser_linux.go @@ -400,6 +400,8 @@ func (p *packetParser) endpointWatcherCallbackFn(obj interface{}) { // Delete from map. p.tcMap.Delete(ifaceKey) } + // Delete from lock map. + p.interfaceLockMap.Delete(ifaceKey) default: // Unknown. p.l.Debug("Unknown event", zap.String("type", event.Type.String())) diff --git a/pkg/plugin/packetparser/packetparser_linux_test.go b/pkg/plugin/packetparser/packetparser_linux_test.go index aa27cfa356..50903852a1 100644 --- a/pkg/plugin/packetparser/packetparser_linux_test.go +++ b/pkg/plugin/packetparser/packetparser_linux_test.go @@ -162,18 +162,24 @@ func TestEndpointWatcherCallbackFn_EndpointDeleted(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() + // Initialize packetParser with both maps. p := &packetParser{ cfg: cfgPodLevelEnabled, l: log.Logger().Named("test"), interfaceLockMap: &sync.Map{}, + tcMap: &sync.Map{}, } - p.tcMap = &sync.Map{} + + // Create test interface attributes. linkAttr := netlink.LinkAttrs{ Name: "test", HardwareAddr: []byte("test"), NetNsID: 1, } key := ifaceToKey(linkAttr) + + // Pre-populate both maps to simulate existing interface + p.interfaceLockMap.Store(key, &sync.Mutex{}) p.tcMap.Store(key, &tcValue{nil, &tc.Object{}}) // Create EndpointDeleted event. @@ -182,10 +188,16 @@ func TestEndpointWatcherCallbackFn_EndpointDeleted(t *testing.T) { Obj: linkAttr, } + // Execute the callback. p.endpointWatcherCallbackFn(e) - _, ok := p.tcMap.Load(key) - assert.False(t, ok) + // Verify both maps are cleaned up. + _, tcMapExists := p.tcMap.Load(key) + _, lockMapExists := p.interfaceLockMap.Load(key) + + // Assert both maps are cleaned up + assert.False(t, tcMapExists, "tcMap entry should be deleted") + assert.False(t, lockMapExists, "interfaceLockMap entry should be deleted") } func TestCreateQdiscAndAttach(t *testing.T) {