Browse Source

control/controlclient: flesh out a recently added comment

Updates tailscale/corp#26058

Change-Id: Ib46161fbb2e79c080f886083665961f02cbf5949
Brad Fitzpatrick 1 year ago
parent
commit
0ed4aa028f
1 changed files with 11 additions and 6 deletions
  1. 11 6
      control/controlclient/auto.go

+ 11 - 6
control/controlclient/auto.go

@@ -620,12 +620,17 @@ func (c *Auto) sendStatus(who string, err error, url string, nm *netmap.NetworkM
 			}
 		}
 		c.observer.SetControlClientStatus(c, *newSt)
-		// Best effort stop retaining the memory now that
-		// we've sent it to the observer (LocalBackend).
-		// We CAS here because the caller goroutine is
-		// doing a Store which we want to want to win
-		// a race. This is only a memory optimization
-		// and is not for correctness:
+
+		// Best effort stop retaining the memory now that we've sent it to the
+		// observer (LocalBackend). We CAS here because the caller goroutine is
+		// doing a Store which we want to win a race. This is only a memory
+		// optimization and is not for correctness.
+		//
+		// If the CAS fails, that means somebody else's Store replaced our
+		// pointer (so mission accomplished: our netmap is no longer retained in
+		// any case) and that Store caller will be responsible for removing
+		// their own netmap (or losing their race too, down the chain).
+		// Eventually the last caller will win this CAS and zero lastStatus.
 		c.lastStatus.CompareAndSwap(newSt, nil)
 	})
 }