-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Clean up interfaceLockMap entries on endpoint deletion #1249
base: main
Are you sure you want to change the base?
Changes from 7 commits
08ec2d8
0fb0297
280a6cb
50c2a15
5912634
6b11dd5
1a1187a
3e78e6b
a4d7e14
31aa74c
fdab1aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,26 +380,38 @@ func (p *packetParser) endpointWatcherCallbackFn(obj interface{}) { | |
} | ||
|
||
iface := event.Obj.(netlink.LinkAttrs) | ||
|
||
ifaceKey := ifaceToKey(iface) | ||
lockMapVal, _ := p.interfaceLockMap.LoadOrStore(ifaceKey, &sync.Mutex{}) | ||
mu := lockMapVal.(*sync.Mutex) | ||
mu.Lock() | ||
defer mu.Unlock() | ||
|
||
switch event.Type { | ||
case endpoint.EndpointCreated: | ||
// Create mutex only when needed | ||
lockMapVal, _ := p.interfaceLockMap.LoadOrStore(ifaceKey, &sync.Mutex{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am curious of the need here. This seems a little bit complex and could a simpler approach be used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, thanks I've removed the Mutex mechanism since we're now using a sequential approach for adding and removing interfaces |
||
mu := lockMapVal.(*sync.Mutex) | ||
mu.Lock() | ||
defer mu.Unlock() | ||
|
||
p.l.Debug("Endpoint created", zap.String("name", iface.Name)) | ||
p.createQdiscAndAttach(iface, Veth) | ||
case endpoint.EndpointDeleted: | ||
// Get the mutex only if it exists | ||
lockMapVal, exists := p.interfaceLockMap.Load(ifaceKey) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bit of a nitpick / question since I'm still new to Go. Is it recommended to stick with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey Kamil! Yeah, I initially used For the test case though, I deliberately kept Let me know if you'd like me to update the main code to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure yeah, let's stick with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, it's resolved |
||
if !exists { | ||
return | ||
} | ||
mu := lockMapVal.(*sync.Mutex) | ||
mu.Lock() | ||
defer mu.Unlock() | ||
|
||
p.l.Debug("Endpoint deleted", zap.String("name", iface.Name)) | ||
// Clean. | ||
// Clean tcMap. | ||
if value, ok := p.tcMap.Load(ifaceKey); ok { | ||
v := value.(*tcValue) | ||
p.clean(v.tc, v.qdisc) | ||
// Delete from map. | ||
p.tcMap.Delete(ifaceKey) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to delete the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted my latest changes, so I brought back the interfaceLockMap and removing the ifacekey from the map |
||
|
||
// Clean interfaceLockMap. | ||
p.interfaceLockMap.Delete(ifaceKey) | ||
default: | ||
// Unknown. | ||
p.l.Debug("Unknown event", zap.String("type", event.Type.String())) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you deleting this? The
interfaceLockMap
allows us to store a per interface lock and we can create/delete multiple qdisc in parallel. This is necessary (in place of a single lock) because large number of pods can come up at the same time, and we should start capturing packets as quickly as possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not clear on this. Why is a per-interface mutex necessary for packetparser to handle concurrent create/delete qdisc operations? As far as I understand, operations on different interfaces shouldn't cause a data race.