From d5bf2012cf499a9c8234a1235d0b681a63ffebe4 Mon Sep 17 00:00:00 2001 From: Abhinandan Prativadi Date: Mon, 24 Jul 2017 11:50:02 -0700 Subject: [PATCH] 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 --- endpoint.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/endpoint.go b/endpoint.go index 111b747352..f56937a84a 100644 --- a/endpoint.go +++ b/endpoint.go @@ -833,6 +833,12 @@ func (ep *endpoint) Delete(force bool) error { logrus.Warnf("failed to recreate endpoint in store %s : %v", name, e) } } + + ep.releaseAddress() + + if err := n.getEpCnt().DecEndpointCnt(); err != nil { + logrus.Warnf("failed to decrement endpoint count for ep %s: %v", ep.ID(), err) + } }() // unwatch for service records @@ -842,12 +848,6 @@ func (ep *endpoint) Delete(force bool) error { return err } - ep.releaseAddress() - - if err := n.getEpCnt().DecEndpointCnt(); err != nil { - logrus.Warnf("failed to decrement endpoint count for ep %s: %v", ep.ID(), err) - } - return nil }