2 files changed,
+33
−3
internal/activator/poolwithdrawal.go
+4 −3
internal/activator/poolwithdrawal_test.go
+29 −0
| index 4c704dd7d..f12fd285f 100644 |
| --- a/internal/activator/poolwithdrawal.go |
| +++ b/internal/activator/poolwithdrawal.go |
| @@ -33,10 +33,11 @@ func (a *Service) PreparePoolWithdrawal(ctx context.Context, rt registry.Route) |
| if b == nil || b.Registry == nil || a.Routes == nil || !rt.PoolWithdrawalSupported() { |
| return pending("ownership") |
| } |
| + current, err := a.Routes.Get(rt.Host) |
| + eligible := a.LocalEligible(rt) |
| a.mu.Lock() |
| defer a.mu.Unlock() |
| - current, err := a.Routes.Get(rt.Host) |
| - if err != nil || current == nil || *current != withdrawalRow(rt) || a.LocalEligible(rt) { |
| + if err != nil || current == nil || *current != withdrawalRow(rt) || eligible { |
| return pending("changed") |
| } |
| if a.shuttingDown { |
| @@ -186,7 +187,7 @@ func (a *Service) poolWithdrawalProof(ctx context.Context, b *ExecBackend, job * |
| return pending("release") |
| } |
| // The local record precedes the remote marker; a failed publish |
| - // leaves an owed obligation, checked above. This clean record |
| + // leaves an owed obligation, checked above. The clean marker |
| // therefore reached S3. A live box's lock cannot pass to another |
| // owner without a marker, so it describes our latest release. |
| } |
| index 436324826..9919e7be6 100644 |
| --- a/internal/activator/poolwithdrawal_test.go |
| +++ b/internal/activator/poolwithdrawal_test.go |
| @@ -249,3 +249,32 @@ func TestPoolWithdrawalOrdinaryAndStatic(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +type withdrawalLookup func(string) (*registry.Route, error) |
| + |
| +func (lookup withdrawalLookup) Get(host string) (*registry.Route, error) { return lookup(host) } |
| + |
| +func TestPoolWithdrawalReadsBeforeServiceLock(t *testing.T) { |
| + s := haService(t, "shop.example.com") |
| + row := withdrawalFixture(t, s) |
| + unlocked := false |
| + s.a.Routes = withdrawalLookup(func(host string) (*registry.Route, error) { |
| + unlocked = s.a.mu.TryLock() |
| + if unlocked { |
| + s.a.mu.Unlock() |
| + } |
| + current := withdrawalRow(row) |
| + current.Pool = "changed" |
| + return ¤t, nil |
| + }) |
| + err := s.a.PreparePoolWithdrawal(t.Context(), row) |
| + if !unlocked { |
| + t.Error("registry read held service mutex") |
| + } |
| + if err == nil || !strings.Contains(err.Error(), "code=changed") { |
| + t.Fatalf("changed row accepted: %v", err) |
| + } |
| + if len(s.a.poolWithdrawals) != 0 || s.a.Fenced(row.Host) { |
| + t.Fatal("changed row started withdrawal") |
| + } |
| +} |