From ee03f83c53f3b44cbedd621ffe889c7a4407dbac Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 30 Nov 2026 12:41:19 -0800 Subject: [PATCH] Preserve map validation cleanup failures --- .../chunk_map_close_error_linux_test.go | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 seaweed-block/core/storage/chunk_map_close_error_linux_test.go diff --git a/seaweed-block/core/storage/chunk_map_close_error_linux_test.go b/seaweed-block/core/storage/chunk_map_close_error_linux_test.go new file mode 100644 index 0000000000..9159cff3da --- /dev/null +++ b/seaweed-block/core/storage/chunk_map_close_error_linux_test.go @@ -0,0 +1,61 @@ +//go:build linux + +package storage + +import ( + "context" + "errors" + "os" + "strconv" + "syscall" + "testing" +) + +func TestChunkMapValidationKeepsTheCloseFailure(t *testing.T) { + for _, failClose := range []bool{false, true} { + t.Run(strconv.FormatBool(failClose), func(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + d := s.v3.pub.current() + crashStore(t, s) + other := d + other.UUID[0] ^= 1 // definite validation refusal, independent of I/O + closed := false + ctx := WithRecoveryProgress(context.Background(), func(phase RecoveryPhase, _ uint64) { + if phase != RecoveryOpenMap || !failClose || closed { + return + } + // Close only this test's map descriptor underneath its os.File. + // The later os.File.Close must report EBADF, exercising the real + // opener's cleanup instead of mocking error composition. + fds, err := os.ReadDir("/proc/self/fd") + if err != nil { + t.Fatal(err) + } + for _, fd := range fds { + target, err := os.Readlink("/proc/self/fd/" + fd.Name()) + if err != nil || target != path+".chunkmap" { + continue + } + n, err := strconv.Atoi(fd.Name()) + if err != nil { + t.Fatal(err) + } + if err := syscall.Close(n); err != nil { + t.Fatal(err) + } + closed = true + return + } + t.Fatal("owned validation handle not found") + }) + m, _, err := openDescriptorMapV3Progress(path+".chunkmap", d, &other, newRecoveryReporter(ctx, RecoveryOpenMap)) + if m != nil { + m.Close() + t.Fatal("invalid fallback identity returned an open map") + } + if !errors.Is(err, ErrMapInvalid) || errors.Is(err, syscall.EBADF) != failClose || closed != failClose { + t.Fatalf("close fault=%v injected=%v: error=%v", failClose, closed, err) + } + }) + } +}