From aee474665e40c0205dd949631b199b4bab59852d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 08:41:33 -0800 Subject: [PATCH 1/3] fix status server immediate shutdown race --- .../core/host/volume/status_server.go | 3 ++- .../volume/status_server_shutdown_test.go | 25 +++++++++++++++++++ seaweed-block/docs/design/invariants.md | 6 +++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 seaweed-block/core/host/volume/status_server_shutdown_test.go diff --git a/seaweed-block/core/host/volume/status_server.go b/seaweed-block/core/host/volume/status_server.go index 713bc55d9f..de3fbe7c37 100644 --- a/seaweed-block/core/host/volume/status_server.go +++ b/seaweed-block/core/host/volume/status_server.go @@ -391,7 +391,8 @@ func (s *StatusServer) Start(addr string) (string, error) { } s.srv = &http.Server{Handler: mux, ReadHeaderTimeout: 5 * time.Second} - go func() { _ = s.srv.Serve(ln) }() + srv := s.srv + go func() { _ = srv.Serve(ln) }() return s.addr, nil } diff --git a/seaweed-block/core/host/volume/status_server_shutdown_test.go b/seaweed-block/core/host/volume/status_server_shutdown_test.go new file mode 100644 index 0000000000..5de9082f07 --- /dev/null +++ b/seaweed-block/core/host/volume/status_server_shutdown_test.go @@ -0,0 +1,25 @@ +package volume + +import ( + "context" + "runtime" + "testing" +) + +// Keep Serve runnable until after Close: starting a listener and immediately +// shutting it down must be safe even if the Serve goroutine has not run yet. +func TestStatusServerImmediateClose(t *testing.T) { + previous := runtime.GOMAXPROCS(1) + defer runtime.GOMAXPROCS(previous) + s := NewStatusServer(NewAdapterProjectionView(stubProjector{}, "v1", "r1", nil)) + if _, err := s.Start("127.0.0.1:0"); err != nil { + t.Fatal(err) + } + if err := s.Close(context.Background()); err != nil { + t.Fatal(err) + } + runtime.Gosched() // let the delayed Serve execute before the test returns + if err := s.Close(context.Background()); err != nil { + t.Fatalf("repeated close: %v", err) + } +} diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index d60d7f1b99..3c72f895a3 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -1110,6 +1110,12 @@ Notes: - B.10 rows are enforced in a library with no production caller; they say nothing about a running volume until a caller is added and its own rows name these. +### B.11 Status listener lifetime + +| ID | Statement | Machine / transition | Enforced in | Test | TLA+ property | Status | +| --- | --- | --- | --- | --- | --- | --- | +| `INV-HTTP-SERVE-LIFETIME-001` | A status listener can close immediately after Start, before Serve runs, without a panic or a race on the mutable server pointer. The goroutine keeps the server instance created by that Start. | Local status listener Start → Close | `core/host/volume/status_server.go` `StatusServer.Start` | `TestStatusServerImmediateClose` (`core/host/volume/status_server_shutdown_test.go`) | Not modeled: local HTTP lifetime, no volume/authority state | ACTIVE | + ## Part C. Change rules How a fix or a feature is calibrated against this model: From 10addd3f10f1528b9675455995cbcdd47a4af891 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 08:48:14 -0800 Subject: [PATCH 2/3] run status listener regression in race CI --- seaweed-block/.github/workflows/test.yml | 17 ++++++++++++----- seaweed-block/docs/design/invariants.md | 6 ------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/seaweed-block/.github/workflows/test.yml b/seaweed-block/.github/workflows/test.yml index d36c022df9..45acfb6525 100644 --- a/seaweed-block/.github/workflows/test.yml +++ b/seaweed-block/.github/workflows/test.yml @@ -19,17 +19,18 @@ concurrency: jobs: test: - # One job, two suites, one runner selection. 'unit' is the Go suite below; + # One job, three suites, one runner selection. 'unit' is the Go suite below; # 'process' runs the process-level tests: real blockmaster, blockvolume and # sw-block against a pinned SeaweedFS release. Those tests are named in # .github/process-level-tests.txt, and every one must PASS, so a test that # skips, fails, never starts or is cut off by the timeout fails the suite. # Tests that need root or systemd are not in the list (see its header). + # 'race' runs the focused status-listener lifetime regression under -race. strategy: fail-fast: false matrix: - suite: [unit, process] - name: ${{ matrix.suite == 'unit' && 'go test (linux)' || 'process-level tests (real binaries)' }} + suite: [unit, process, race] + name: ${{ matrix.suite == 'unit' && 'go test (linux)' || (matrix.suite == 'race' && 'go test (race)' || 'process-level tests (real binaries)') }} # The suite writes heavily to the runner disk (real files, fsync), so a # Draft PR skips it; its author tests locally until the PR is ready. if: github.event_name == 'push' || !github.event.pull_request.draft @@ -38,10 +39,10 @@ jobs: # GitHub-hosted runner. runs-on: ${{ (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && 'tp04-seaweed-block' || 'ubuntu-latest' }} # process: 44 tests in 4 parallel shards of about 13 min each (55 min in sequence). - timeout-minutes: ${{ matrix.suite == 'unit' && 40 || 90 }} + timeout-minutes: ${{ matrix.suite == 'race' && 10 || (matrix.suite == 'unit' && 40 || 90) }} env: # Pure-Go build: no package in the default build needs cgo, and the - # hosted runner should not depend on a C toolchain being present. + # default suite does not depend on a C toolchain; the race step opts in. CGO_ENABLED: "0" steps: - name: Checkout @@ -97,6 +98,12 @@ jobs: if: matrix.suite == 'unit' run: go vet ./... + - name: Race status listener shutdown + if: matrix.suite == 'race' + env: + CGO_ENABLED: "1" + run: go test -race ./core/host/volume -run '^TestStatusServerImmediateClose$' -count=50 -timeout=2m + - name: Test default configuration if: matrix.suite == 'unit' # The runner disk is shared, so the long, disk-heavy, timing-sensitive diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 3c72f895a3..d60d7f1b99 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -1110,12 +1110,6 @@ Notes: - B.10 rows are enforced in a library with no production caller; they say nothing about a running volume until a caller is added and its own rows name these. -### B.11 Status listener lifetime - -| ID | Statement | Machine / transition | Enforced in | Test | TLA+ property | Status | -| --- | --- | --- | --- | --- | --- | --- | -| `INV-HTTP-SERVE-LIFETIME-001` | A status listener can close immediately after Start, before Serve runs, without a panic or a race on the mutable server pointer. The goroutine keeps the server instance created by that Start. | Local status listener Start → Close | `core/host/volume/status_server.go` `StatusServer.Start` | `TestStatusServerImmediateClose` (`core/host/volume/status_server_shutdown_test.go`) | Not modeled: local HTTP lifetime, no volume/authority state | ACTIVE | - ## Part C. Change rules How a fix or a feature is calibrated against this model: From 6e967bc8b4cb1396907a561cad3401a9f4dd0b0f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 08:49:53 -0800 Subject: [PATCH 3/3] keep status regression in the existing unit suite --- seaweed-block/.github/workflows/test.yml | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/seaweed-block/.github/workflows/test.yml b/seaweed-block/.github/workflows/test.yml index 45acfb6525..d36c022df9 100644 --- a/seaweed-block/.github/workflows/test.yml +++ b/seaweed-block/.github/workflows/test.yml @@ -19,18 +19,17 @@ concurrency: jobs: test: - # One job, three suites, one runner selection. 'unit' is the Go suite below; + # One job, two suites, one runner selection. 'unit' is the Go suite below; # 'process' runs the process-level tests: real blockmaster, blockvolume and # sw-block against a pinned SeaweedFS release. Those tests are named in # .github/process-level-tests.txt, and every one must PASS, so a test that # skips, fails, never starts or is cut off by the timeout fails the suite. # Tests that need root or systemd are not in the list (see its header). - # 'race' runs the focused status-listener lifetime regression under -race. strategy: fail-fast: false matrix: - suite: [unit, process, race] - name: ${{ matrix.suite == 'unit' && 'go test (linux)' || (matrix.suite == 'race' && 'go test (race)' || 'process-level tests (real binaries)') }} + suite: [unit, process] + name: ${{ matrix.suite == 'unit' && 'go test (linux)' || 'process-level tests (real binaries)' }} # The suite writes heavily to the runner disk (real files, fsync), so a # Draft PR skips it; its author tests locally until the PR is ready. if: github.event_name == 'push' || !github.event.pull_request.draft @@ -39,10 +38,10 @@ jobs: # GitHub-hosted runner. runs-on: ${{ (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && 'tp04-seaweed-block' || 'ubuntu-latest' }} # process: 44 tests in 4 parallel shards of about 13 min each (55 min in sequence). - timeout-minutes: ${{ matrix.suite == 'race' && 10 || (matrix.suite == 'unit' && 40 || 90) }} + timeout-minutes: ${{ matrix.suite == 'unit' && 40 || 90 }} env: # Pure-Go build: no package in the default build needs cgo, and the - # default suite does not depend on a C toolchain; the race step opts in. + # hosted runner should not depend on a C toolchain being present. CGO_ENABLED: "0" steps: - name: Checkout @@ -98,12 +97,6 @@ jobs: if: matrix.suite == 'unit' run: go vet ./... - - name: Race status listener shutdown - if: matrix.suite == 'race' - env: - CGO_ENABLED: "1" - run: go test -race ./core/host/volume -run '^TestStatusServerImmediateClose$' -count=50 -timeout=2m - - name: Test default configuration if: matrix.suite == 'unit' # The runner disk is shared, so the long, disk-heavy, timing-sensitive