costela / hcloud-ip-floater

k8s controller for Hetzner Cloud floating IPs
GNU General Public License v3.0
53 stars 10 forks source link

Fix race condition that can lead to a deadlock #13

Closed eplightning closed 4 years ago

eplightning commented 4 years ago

There's a possible race condition that can lead to a deadlock which completely stops reconcilation process. It can happen when reconcilation process enters loop (locks fipsMu and then attMu each iteration) and service controller executes AttachToNode function which locks attMu and then locks fipsMu inside syncLoopingIPs.

This PR changes deferred unlock to direct unlock call right after stopping iteration over attachments map.

Fixes #10

eplightning commented 4 years ago

Looking at syncFloatingIPs again I noticed that it's actually accessing attachments map there (in elseif) - which should be protected by a lock.

I'll fix this later today.