Browse code

d/libnetwork: fix (*Controller).getLBIndex panics

Check the serviceBinding's deleted flag to guard against the service
getting deleted before we locked its mutex, which would make it futile
to look up the load balancers. And guard against dereferencing a nil
*loadBalancer in general.

Signed-off-by: Cory Snider <csnider@mirantis.com>

Cory Snider authored on 2026/01/30 08:14:56
Showing 1 changed files
... ...
@@ -160,9 +160,14 @@ func (c *Controller) getLBIndex(sid, nid string, ingressPorts []*PortConfig) int
160 160
 	}
161 161
 
162 162
 	s.Lock()
163
+	defer s.Unlock()
164
+	if s.deleted {
165
+		return 0
166
+	}
163 167
 	lb := s.loadBalancers[nid]
164
-	s.Unlock()
165
-
168
+	if lb == nil {
169
+		return 0
170
+	}
166 171
 	return int(lb.fwMark)
167 172
 }
168 173