Because it loaded the Endpoint object from store and operated
on that copy rather than its own receiver, sbJoin couldn't
successfully roll back on error if the Endpoint was not included
in the Sandbox's list of endpoints, or its current state had
not been written to store after the error occurred.
So, for example, releaseOSSboxResources() would not be called
to delete interfaces created in the container's netns.
Signed-off-by: Rob Murray <rob.murray@docker.com>
| ... | ... |
@@ -100,7 +100,7 @@ func (sb *Sandbox) clearDefaultGW() error {
|
| 100 | 100 |
if ep = sb.getEndpointInGWNetwork(); ep == nil {
|
| 101 | 101 |
return nil |
| 102 | 102 |
} |
| 103 |
- if err := ep.sbLeave(context.TODO(), sb, false); err != nil {
|
|
| 103 |
+ if err := ep.sbLeave(context.TODO(), sb, ep.getNetwork(), false); err != nil {
|
|
| 104 | 104 |
return fmt.Errorf("container %s: endpoint leaving GW Network failed: %v", sb.containerID, err)
|
| 105 | 105 |
} |
| 106 | 106 |
if err := ep.Delete(context.TODO(), false); err != nil {
|
| ... | ... |
@@ -753,20 +753,20 @@ func (ep *Endpoint) Leave(ctx context.Context, sb *Sandbox) error {
|
| 753 | 753 |
sb.joinLeaveMu.Lock() |
| 754 | 754 |
defer sb.joinLeaveMu.Unlock() |
| 755 | 755 |
|
| 756 |
- return ep.sbLeave(ctx, sb, false) |
|
| 757 |
-} |
|
| 758 |
- |
|
| 759 |
-func (ep *Endpoint) sbLeave(ctx context.Context, sb *Sandbox, force bool) error {
|
|
| 760 | 756 |
n, err := ep.getNetworkFromStore() |
| 761 | 757 |
if err != nil {
|
| 762 | 758 |
return fmt.Errorf("failed to get network from store during leave: %v", err)
|
| 763 | 759 |
} |
| 764 | 760 |
|
| 765 |
- ep, err = n.getEndpointFromStore(ep.ID()) |
|
| 761 |
+ storedEp, err := n.getEndpointFromStore(ep.ID()) |
|
| 766 | 762 |
if err != nil {
|
| 767 | 763 |
return fmt.Errorf("failed to get endpoint from store during leave: %v", err)
|
| 768 | 764 |
} |
| 769 | 765 |
|
| 766 |
+ return storedEp.sbLeave(ctx, sb, n, false) |
|
| 767 |
+} |
|
| 768 |
+ |
|
| 769 |
+func (ep *Endpoint) sbLeave(ctx context.Context, sb *Sandbox, n *Network, force bool) error {
|
|
| 770 | 770 |
ctx = log.WithLogger(ctx, log.G(ctx).WithFields(log.Fields{
|
| 771 | 771 |
"nid": n.ID(), |
| 772 | 772 |
"net": n.Name(), |
| ... | ... |
@@ -920,7 +920,7 @@ func (ep *Endpoint) Delete(ctx context.Context, force bool) error {
|
| 920 | 920 |
} |
| 921 | 921 |
|
| 922 | 922 |
if sb != nil {
|
| 923 |
- if e := ep.sbLeave(context.WithoutCancel(ctx), sb, force); e != nil {
|
|
| 923 |
+ if e := ep.sbLeave(context.WithoutCancel(ctx), sb, n, force); e != nil {
|
|
| 924 | 924 |
log.G(ctx).Warnf("failed to leave sandbox for endpoint %s : %v", name, e)
|
| 925 | 925 |
} |
| 926 | 926 |
} |