carlos / platform Public

region-ha p1b-1: the takeover oracle's EC2 client makes one request per describe

The SDK's default retryer made up to three attempts, bypassing the
confirmer's ten-second negative cache. Retries are off for this client;
a transport-level test pins one request, none in the cache window, one after.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev f60f129ad82138d2fff6cfd01f9ae8ad9d4d53d1 parent 23d219c
2 files changed, +51 −2
  • internal/host/hatakeover.go +3 −2
  • internal/host/hatakeover_wiring_test.go +48 −0
diff --git a/internal/host/hatakeover.go b/internal/host/hatakeover.go
index 9430b06bb..701901fe8 100644
--- a/internal/host/hatakeover.go
+++ b/internal/host/hatakeover.go
@@ -30,9 +30,10 @@ func haCloudSelf() boxid.Cloud {
}
// haTakeoverEC2 builds the oracle's EC2 client for region, through root's
-// AWS loader.
+// AWS loader. The SDK's own retries are off: the confirmer's ten-second
+// negative cache is the only retry, so one call is one request.
func haTakeoverEC2(ctx context.Context, region string) (termfence.EC2, error) {
- cfg, err := rootaws.LoadDefaultConfig(ctx, awsconfig.WithRegion(region))
+ cfg, err := rootaws.LoadDefaultConfig(ctx, awsconfig.WithRegion(region), awsconfig.WithRetryMaxAttempts(1))
if err != nil {
return nil, err
}
diff --git a/internal/host/hatakeover_wiring_test.go b/internal/host/hatakeover_wiring_test.go
index 2d8862483..15d522cf4 100644
--- a/internal/host/hatakeover_wiring_test.go
+++ b/internal/host/hatakeover_wiring_test.go
@@ -2,9 +2,14 @@ package host
import (
"context"
+ "io"
+ "net/http"
+ "net/http/httptest"
"os"
"strings"
+ "sync/atomic"
"testing"
+ "time"
"github.com/carlosframework/platform/internal/boxid"
"github.com/carlosframework/platform/internal/hafresh"
@@ -55,3 +60,46 @@ func TestHAOwnerConfirmerReadsTheLateIdentity(t *testing.T) {
t.Fatal("no EC2 client builder")
}
}
+
+// The oracle's describe is one HTTP request, not the SDK's three: the
+// confirmer's ten-second negative cache is the only retry. The client is the
+// production-built one, aimed at a server that answers 503.
+func TestHAOwnerConfirmerDescribeIsOneRequest(t *testing.T) {
+ t.Cleanup(lease.ProcessStateForTest())
+ var requests atomic.Int32
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ requests.Add(1)
+ w.WriteHeader(http.StatusServiceUnavailable)
+ io.WriteString(w, `<Response><Errors><Error><Code>RequestLimitExceeded</Code><Message>slow down</Message></Error></Errors><RequestID>req-1</RequestID></Response>`)
+ }))
+ defer srv.Close()
+ t.Setenv("AWS_ENDPOINT_URL_EC2", srv.URL)
+ t.Setenv("AWS_ACCESS_KEY_ID", "AKIDEXAMPLE")
+ t.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
+ t.Setenv("AWS_SESSION_TOKEN", "")
+ t.Setenv("AWS_PROFILE", "")
+ t.Setenv("AWS_EC2_METADATA_DISABLED", "true")
+ lease.SetSelf(hafresh.Self{Ref: "a", IID: "i-a", Account: "111122223333", Region: "eu-west-1"})
+
+ now := time.Date(2026, 10, 27, 12, 0, 0, 0, time.UTC)
+ c := haOwnerConfirmer()
+ c.Now = func() time.Time { return now }
+ c.Logf = func(string, ...any) {}
+
+ if yes, err := c.Terminated(context.Background(), "i-b"); yes || err == nil {
+ t.Fatalf("a throttled describe answered %v, %v", yes, err)
+ }
+ if got := requests.Load(); got != 1 {
+ t.Fatalf("the first call made %d requests, want 1 (the SDK retried)", got)
+ }
+ now = now.Add(termfence.ConfirmNegativeTTL - time.Second)
+ c.Terminated(context.Background(), "i-b")
+ if got := requests.Load(); got != 1 {
+ t.Fatalf("inside the negative cache: %d requests, want 1", got)
+ }
+ now = now.Add(2 * time.Second)
+ c.Terminated(context.Background(), "i-b")
+ if got := requests.Load(); got != 2 {
+ t.Fatalf("after the negative cache: %d requests, want 2", got)
+ }
+}