From 804f93bdff7c29493284844cd44dd5df80469627 Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Thu, 14 Jul 2016 22:51:06 -0400 Subject: [PATCH 1/2] Fix update endpoint cnt to store Signed-off-by: Lei Jitang --- libnetwork/endpoint_cnt.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libnetwork/endpoint_cnt.go b/libnetwork/endpoint_cnt.go index 702fbac8d7..9cc62324dd 100644 --- a/libnetwork/endpoint_cnt.go +++ b/libnetwork/endpoint_cnt.go @@ -113,6 +113,9 @@ func (ec *endpointCnt) updateStore() error { if store == nil { return fmt.Errorf("store not found for scope %s on endpoint count update", ec.DataScope()) } + // make a copy of count and n to avoid being overwritten by store.GetObject + count := ec.EndpointCnt() + n := ec.n for { if err := ec.n.getController().updateToStore(ec); err == nil || err != datastore.ErrKeyModified { return err @@ -120,6 +123,10 @@ func (ec *endpointCnt) updateStore() error { if err := store.GetObject(datastore.Key(ec.Key()...), ec); err != nil { return fmt.Errorf("could not update the kvobject to latest on endpoint count update: %v", err) } + ec.Lock() + ec.Count = count + ec.n = n + ec.Unlock() } } From 4999c5707d0d60f2b832235c7aca73fa43485d3b Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Thu, 14 Jul 2016 22:52:44 -0400 Subject: [PATCH 2/2] Fix endpoint cnt decline overflow Signed-off-by: Lei Jitang --- libnetwork/endpoint_cnt.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libnetwork/endpoint_cnt.go b/libnetwork/endpoint_cnt.go index 9cc62324dd..c63d06abe0 100644 --- a/libnetwork/endpoint_cnt.go +++ b/libnetwork/endpoint_cnt.go @@ -143,7 +143,9 @@ retry: if inc { ec.Count++ } else { - ec.Count-- + if ec.Count > 0 { + ec.Count-- + } } ec.Unlock()