Browse code

Network disconnect: log rather than error on gateway update

During a network disconnect, log rather than returning an error
if it's not possible to set up a new gateway.

This restores the behaviour from before commit 53390f8 ("Put
clearNetworkResources() inline in its only caller"). It's not
ideal, but by the time new gateways are selected the old
endpoint has been disconnected - and nothing puts things back.
Until that's cleaned up, a broken state is inevitable, but
letting endpoint deletion complete means the container can
be restarted or re-connected to the network without a zombie
endpoint causing further issues.

Signed-off-by: Rob Murray <rob.murray@docker.com>

Rob Murray authored on 2025/11/26 01:41:18
Showing 1 changed files
... ...
@@ -745,10 +745,12 @@ func (ep *Endpoint) Leave(ctx context.Context, sb *Sandbox) error {
745 745
 
746 746
 func (ep *Endpoint) sbLeave(ctx context.Context, sb *Sandbox, n *Network, force bool) error {
747 747
 	ctx = log.WithLogger(ctx, log.G(ctx).WithFields(log.Fields{
748
-		"nid": n.ID(),
748
+		"nid": stringid.TruncateID(n.ID()),
749 749
 		"net": n.Name(),
750
-		"eid": ep.ID(),
750
+		"eid": epShortId(ep),
751 751
 		"ep":  ep.Name(),
752
+		"sid": stringid.TruncateID(sb.ID()),
753
+		"cid": stringid.TruncateID(sb.ContainerID()),
752 754
 	}))
753 755
 
754 756
 	sb.mu.Lock()
... ...
@@ -829,7 +831,13 @@ func (ep *Endpoint) sbLeave(ctx context.Context, sb *Sandbox, n *Network, force
829 829
 	if needNewGwEp {
830 830
 		gwepAfter4, gwepAfter6 = sb.getGatewayEndpoint()
831 831
 		if err := sb.updateGateway(gwepAfter4, gwepAfter6); err != nil {
832
-			return fmt.Errorf("updating gateway endpoint: %w", err)
832
+			// Don't return an error here without adding proper rollback of the work done above.
833
+			// See https://github.com/moby/moby/issues/51578
834
+			log.G(ctx).WithFields(log.Fields{
835
+				"gw4":   epShortId(gwepAfter4),
836
+				"gw6":   epShortId(gwepAfter6),
837
+				"error": err,
838
+			}).Warn("Configuring gateway after network disconnect")
833 839
 		}
834 840
 	}
835 841