Skip to content

Commit 745cc37

Browse files
committed
Ensuring endpoint resources are freed even on delete failures
Came across a code path where we might not be releasing ip address assigned to an endpoint if we have a failure with deleteEndpoint. Even if there is a failure it is better to release the resource rather than holding them. This might lead to issues where ip never gets released even though the container has exited and the only way of recovery is a reload. Signed-off-by: Abhinandan Prativadi <[email protected]>
1 parent 6426d1e commit 745cc37

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

endpoint.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ func (ep *endpoint) Delete(force bool) error {
822822
}
823823
}
824824

825-
if err = n.getController().deleteFromStore(ep); err != nil {
825+
if err = n.getController().deleteFromStore(ep); err != nil && !force {
826826
return err
827827
}
828828

sandbox.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ func (sb *sandbox) Statistics() (map[string]*types.InterfaceStatistics, error) {
182182
}
183183

184184
func (sb *sandbox) Delete() error {
185-
return sb.delete(false)
185+
return sb.delete()
186186
}
187187

188-
func (sb *sandbox) delete(force bool) error {
188+
func (sb *sandbox) delete() error {
189189
sb.Lock()
190190
if sb.inDelete {
191191
sb.Unlock()
@@ -208,10 +208,10 @@ func (sb *sandbox) delete(force bool) error {
208208
retain := false
209209
for _, ep := range sb.getConnectedEndpoints() {
210210
// gw network endpoint detach and removal are automatic
211-
if ep.endpointInGWNetwork() && !force {
211+
if ep.endpointInGWNetwork() {
212212
continue
213213
}
214-
// Retain the sanbdox if we can't obtain the network from store.
214+
// Retain the sandbox if we can't obtain the network from store.
215215
if _, err := c.getNetworkFromStore(ep.getNetwork().ID()); err != nil {
216216
if c.isDistributedControl() {
217217
retain = true
@@ -220,13 +220,11 @@ func (sb *sandbox) delete(force bool) error {
220220
continue
221221
}
222222

223-
if !force {
224-
if err := ep.Leave(sb); err != nil {
225-
logrus.Warnf("Failed detaching sandbox %s from endpoint %s: %v\n", sb.ID(), ep.ID(), err)
226-
}
223+
if err := ep.Leave(sb); err != nil {
224+
logrus.Warnf("Failed detaching sandbox %s from endpoint %s: %v\n", sb.ID(), ep.ID(), err)
227225
}
228226

229-
if err := ep.Delete(force); err != nil {
227+
if err := ep.Delete(true); err != nil {
230228
logrus.Warnf("Failed deleting endpoint %s: %v\n", ep.ID(), err)
231229
}
232230
}

sandbox_store.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func (c *controller) sandboxCleanup(activeSandboxes map[string]interface{}) {
279279

280280
if _, ok := activeSandboxes[sb.ID()]; !ok {
281281
logrus.Infof("Removing stale sandbox %s (%s)", sb.id, sb.containerID)
282-
if err := sb.delete(true); err != nil {
282+
if err := sb.delete(); err != nil {
283283
logrus.Errorf("Failed to delete sandbox %s while trying to cleanup: %v", sb.id, err)
284284
}
285285
continue

0 commit comments

Comments
 (0)