From bd8b083d52cb7d85d7bfc9aa05be3adde1ce37de Mon Sep 17 00:00:00 2001 From: CMGS Date: Mon, 28 Sep 2026 17:31:23 +0800 Subject: [PATCH] fix(sandboxd): a claim that requires a promoted template is not sent to a warm peer at quota either #264 kept the warm redirect out of the missing-template branch; the quota branch after ClaimProvision still offered the warm candidates without require_promoted. A required claim at quota answers 429. --- sandboxd/server/server.go | 2 +- sandboxd/server/server_test.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/sandboxd/server/server.go b/sandboxd/server/server.go index 11db0730..d464b975 100644 --- a/sandboxd/server/server.go +++ b/sandboxd/server/server.go @@ -262,7 +262,7 @@ func (s *Server) handleClaim(w http.ResponseWriter, r *http.Request) { } sb, err = s.mgr.ClaimProvision(r.Context(), key, o) } - if errors.Is(err, pool.ErrQuota) && s.placer != nil && !req.NoRedirect && + if errors.Is(err, pool.ErrQuota) && s.placer != nil && !req.NoRedirect && !req.RequirePromoted && s.writeRedirect(w, s.placer.Candidates(key.Hash())) { return } diff --git a/sandboxd/server/server_test.go b/sandboxd/server/server_test.go index d6225f85..bc7a7bea 100644 --- a/sandboxd/server/server_test.go +++ b/sandboxd/server/server_test.go @@ -1729,15 +1729,18 @@ func TestARequiredPromotedClaimIsNeverSentToAWarmPeer(t *testing.T) { for _, tt := range []struct { name string require bool + provision error wantStatus int wantWarm bool }{ - {"a plain claim follows the warm peer", false, http.StatusOK, true}, - {"a required promoted claim answers 404 rather than a warm peer", true, http.StatusNotFound, false}, + {"a plain claim follows the warm peer", false, pool.ErrUnknownTemplate, http.StatusOK, true}, + {"a required promoted claim answers 404 rather than a warm peer", true, pool.ErrUnknownTemplate, http.StatusNotFound, false}, + {"a plain claim at quota follows the warm peer", false, pool.ErrQuota, http.StatusOK, true}, + {"a required promoted claim at quota answers 429 rather than a warm peer", true, pool.ErrQuota, http.StatusTooManyRequests, false}, } { t.Run(tt.name, func(t *testing.T) { mgr := &fakeManager{claim: func(context.Context, types.PoolKey, time.Duration) (*types.Sandbox, error) { - return nil, pool.ErrUnknownTemplate + return nil, tt.provision }} srv := New("sekret", nil, "node-a:7777", mgr, &fakeDialer{}, &fakePlacer{addrs: []string{"warm:7777"}}, nil, nil, nil) ts := httptest.NewServer(srv.Handler())