From 073bb08ddf551629cda820c150640f6d76d285c8 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 04:26:00 -0800 Subject: [PATCH] fix(sw-block): clamp each request's client wait to the loop's deadline The client's wait for an answer was sent + per + cushion, with per computed before sent was sampled: a pause between the two moved the wait past the loop's deadline. It is now min(deadline, sent + per + cushion), so it never reaches past --timeout (INV-CLI-CHUNK-LOOP-003). Test isolation: when runChunkWithin's bound fails a test, it now joins the command (bounded) before the earlier cleanups restore the package globals. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/cmd/sw-block/chunk_loop.go | 3 ++- seaweed-block/cmd/sw-block/chunk_request_loop_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/seaweed-block/cmd/sw-block/chunk_loop.go b/seaweed-block/cmd/sw-block/chunk_loop.go index 8328ea6bec..63c21dd8e4 100644 --- a/seaweed-block/cmd/sw-block/chunk_loop.go +++ b/seaweed-block/cmd/sw-block/chunk_loop.go @@ -105,7 +105,8 @@ func chunkPostLoop(name, statusAddr, route string, timeout time.Duration, body m } sent := time.Now() var out, errb bytes.Buffer - code := chunkPostUntil(name, statusAddr, route, per, sent.Add(per+cushion), body, &out, &errb) + // the client's wait never reaches past the deadline, however late after computing per the request is sent + code := chunkPostUntil(name, statusAddr, route, per, minTime(deadline, sent.Add(per+cushion)), body, &out, &errb) var e chunkErrBody // repeated only after a retryable or outcome_unknown answer (INV-CLI-CHUNK-LOOP-001) retry := code != ops.VolumeStatusExitOK && json.Unmarshal(out.Bytes(), &e) == nil && e.Code != "" && diff --git a/seaweed-block/cmd/sw-block/chunk_request_loop_test.go b/seaweed-block/cmd/sw-block/chunk_request_loop_test.go index 3277e78f18..7e676b8fcf 100644 --- a/seaweed-block/cmd/sw-block/chunk_request_loop_test.go +++ b/seaweed-block/cmd/sw-block/chunk_request_loop_test.go @@ -207,6 +207,14 @@ func runChunkWithin(t *testing.T, limit time.Duration, args ...string) (int, str case r := <-done: return r.code, r.out, r.err case <-time.After(limit): + // join the command (bounded) before the earlier cleanups restore the package globals it reads; cleanups run + // last-registered first + t.Cleanup(func() { + select { + case <-done: + case <-time.After(10 * time.Second): + } + }) t.Fatalf("the command did not return within %v: the loop does not end at its --timeout", limit) return 0, "", "" }