From 20e7f5fa9af38939c19287e00c8ea35ac6e3f0e4 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 5 Dec 2026 13:44:09 -0800 Subject: [PATCH] seaweed-block: failover keeps exit 3 for a caller deadline before send A failover whose caller deadline passed before the request was sent (e.g. a master that never completes the handshake) is Recover under the failover contract, so the command prints result=unknown and asks the operator to read the current line. The canonical projection gave it exit 1, which the help text reserves for a definite answer, while v1.1.x returned 3. Add the failover legacy row next to the unsent remote-failure one so the exit matches the printed outcome. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/cmd/sw-block/failover_test.go | 37 +++++++++++++++++++ .../core/rpc/answer/exit_projection.go | 1 + .../core/rpc/answer/exit_projection_test.go | 5 ++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/seaweed-block/cmd/sw-block/failover_test.go b/seaweed-block/cmd/sw-block/failover_test.go index 572e708130..1303168cb6 100644 --- a/seaweed-block/cmd/sw-block/failover_test.go +++ b/seaweed-block/cmd/sw-block/failover_test.go @@ -11,6 +11,7 @@ import ( "encoding/pem" "errors" "math/big" + "net" "os" "os/exec" "path/filepath" @@ -170,6 +171,42 @@ func TestOpsFailoverReportsAnUnknownOutcome(t *testing.T) { } } +// A master that never answers the handshake leaves the call unsent when the +// caller's deadline passes; the operator must still read the line first. +func TestOpsFailoverUnsentCallerDeadlineIsUnknown(t *testing.T) { + cert, key, ca := writeClientIdentity(t, t.TempDir()) + t.Setenv(link.EnvTLSCert, cert) + t.Setenv(link.EnvTLSKey, key) + t.Setenv(link.EnvTLSCA, ca) + silent, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Fatal(err) + } + held := make(chan net.Conn, 16) + go func() { + for { + conn, err := silent.Accept() + if err != nil { + close(held) + return + } + held <- conn + } + }() + t.Cleanup(func() { + silent.Close() + for conn := range held { + conn.Close() + } + }) + args := failoverArgs("--timeout", "300ms") + args[3] = silent.Addr().String() + var out, errb bytes.Buffer + if rc := run(args, &out, &errb); rc != 3 || !strings.Contains(out.String(), "result=unknown") { + t.Fatalf("rc=%d stdout=%q stderr=%q; want 3 and result=unknown", rc, out.String(), errb.String()) + } +} + // The admin command never dials without a complete, valid client identity: // unset, partial or unreadable TLS settings are refused locally (exit 2, no // call); a valid identity makes the call. diff --git a/seaweed-block/core/rpc/answer/exit_projection.go b/seaweed-block/core/rpc/answer/exit_projection.go index 51d85c5fc4..f084a5a598 100644 --- a/seaweed-block/core/rpc/answer/exit_projection.go +++ b/seaweed-block/core/rpc/answer/exit_projection.go @@ -23,6 +23,7 @@ type LegacyExit struct { var legacyExits = []LegacyExit{ {Failover, "remote_unavailable", 3, "docs/standalone-deployment.md", "Failover requires reading the current authority line before another move even when its RPC was unsent.", "v1.2"}, + {Failover, "deadline_exceeded", 3, "docs/standalone-deployment.md", "A caller deadline before sending also requires reading the current authority line before another move.", "v1.2"}, {ChunkVerify, "outcome_unknown", 1, "docs/standalone-deployment.md", "Incomplete verification must not share exit 3 with a completed scan containing findings; JSON retains the failure class.", "v1.2"}, {VolumeCreate, "bad_request", 78, "docs/standalone-deployment.md", "Create documents server refusal as 78; local argument parsing remains 2.", "v1.2"}, {VolumeResolve, "bad_request", 78, "docs/standalone-deployment.md", "Resolve documents definite server refusal as 78; local argument parsing remains 2.", "v1.2"}, diff --git a/seaweed-block/core/rpc/answer/exit_projection_test.go b/seaweed-block/core/rpc/answer/exit_projection_test.go index ca0297912a..d337256d00 100644 --- a/seaweed-block/core/rpc/answer/exit_projection_test.go +++ b/seaweed-block/core/rpc/answer/exit_projection_test.go @@ -48,7 +48,7 @@ func TestCanonicalExitProjectionGrid(t *testing.T) { if contract == answer.ChunkVerify && row.name == "unknown" { want = 1 } - if contract == answer.Failover && row.name == "unsent" { + if contract == answer.Failover && (row.name == "unsent" || row.name == "caller-deadline") { want = 3 } if (contract == answer.VolumeCreate || contract == answer.VolumeResolve) && row.name == "unknown" { @@ -69,6 +69,8 @@ func TestCanonicalExitProjectionGrid(t *testing.T) { } func TestEveryLegacyExitHasADocumentedGridRow(t *testing.T) { + expired, cancel := context.WithTimeout(context.Background(), -time.Second) + defer cancel() expected := []struct { contract answer.Contract err error @@ -76,6 +78,7 @@ func TestEveryLegacyExitHasADocumentedGridRow(t *testing.T) { exit int }{ {answer.Failover, answer.Record(answer.Unsent, refusedDial(t)), answer.Unsent, 3}, + {answer.Failover, answer.RecordContext(expired, answer.Unsent, expired.Err()), answer.Unsent, 3}, {answer.ChunkVerify, resetConnection(t), answer.PossiblyAdmitted, 1}, {answer.VolumeCreate, status.Error(codes.InvalidArgument, "server refused"), answer.PossiblyAdmitted, 78}, {answer.VolumeResolve, status.Error(codes.InvalidArgument, "server refused"), answer.PossiblyAdmitted, 78},