SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
filer: do not 404 a TUS session on a transient chunk-load failure (#11153)
Chris Lucda43f19764d
diff --git a/weed/server/filer_grpc_server_rename_test.go b/weed/server/filer_grpc_server_rename_test.goindex 57757ca8db..2c36c97858 100644--- a/weed/server/filer_grpc_server_rename_test.go+++ b/weed/server/filer_grpc_server_rename_test.go@@ -29,6 +29,7 @@ type renameTestStore struct {findCalls map[string]intcommitErr errordeleteErr error+ listErr error // simulates a transient store/RPC failure from a directory listingfindDelay time.Duration // optional: widen check-then-act windows in tests}@@ -107,6 +108,11 @@ func (s *renameTestStore) DeleteFolderChildren(_ context.Context, p util.FullPatfunc (s *renameTestStore) listDirectoryEntries(dirPath util.FullPath, startFileName string, includeStartFile bool, limit int64, prefix string, eachEntryFunc filer.ListEachEntryFunc) (string, error) {s.mu.Lock()+ if s.listErr != nil {+ err := s.listErr+ s.mu.Unlock()+ return "", err+ }var entries []*filer.Entryfor path, entry := range s.entries {if path == string(dirPath) {diff --git a/weed/server/filer_server_tus_handlers.go b/weed/server/filer_server_tus_handlers.goindex e2d9aa2186..a48ad142c1 100644--- a/weed/server/filer_server_tus_handlers.go+++ b/weed/server/filer_server_tus_handlers.go@@ -99,6 +99,10 @@ func (fs *FilerServer) tusHandler(w http.ResponseWriter, r *http.Request) {}if err := fs.loadTusSessionChunks(ctx, session); err != nil {glog.Errorf("Failed to load TUS session %s chunks: %v", uploadID, err)+ if !errors.Is(err, filer_pb.ErrNotFound) {+ http.Error(w, "Failed to load upload state", http.StatusInternalServerError)+ return+ }writeTusSessionNotFound(w, r.Method)return}diff --git a/weed/server/filer_server_tus_transient_test.go b/weed/server/filer_server_tus_transient_test.gonew file mode 100644index 0000000000..b10dc0249b--- /dev/null+++ b/weed/server/filer_server_tus_transient_test.go@@ -0,0 +1,86 @@+package weed_server++import (+ "context"+ "net/http"+ "net/http/httptest"+ "testing"++ "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"+ "github.com/seaweedfs/seaweedfs/weed/util"+)++// TestFilerServer_tusHandler_TransientChunkLoadFailure reproduces #11151: a+// transient failure listing a session's chunk directory (volume timeout,+// canceled context) must not be reported as 404/204, since readTusSessionInfo+// already proved the session exists. A false "not found" makes a compliant+// client discard a live session and orphan every chunk it committed.+func TestFilerServer_tusHandler_TransientChunkLoadFailure(t *testing.T) {+ tests := []struct {+ name string+ method string+ }{+ {"HEAD", http.MethodHead},+ {"PATCH", http.MethodPatch},+ {"DELETE", http.MethodDelete},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ fs, store := newTusTestServer(t, map[string]string{tusTestUploadID: "/buckets/data/file.bin"})+ store.listErr = context.Canceled++ headers := map[string]string{"Authorization": "Bearer " + signFilerToken(t, tusTestWriteKey, nil, nil)}+ if tt.method == http.MethodHead {+ headers["Authorization"] = "Bearer " + signFilerToken(t, tusTestReadKey, nil, nil)+ }+ if tt.method == http.MethodPatch {+ headers["Content-Type"] = "application/offset+octet-stream"+ headers["Upload-Offset"] = "0"+ }+ req := tusRequest(tt.method, "/.tus/.uploads/"+tusTestUploadID, headers, "")+ rec := httptest.NewRecorder()+ fs.tusHandler(rec, req)++ if rec.Code == http.StatusNotFound || rec.Code == http.StatusNoContent {+ t.Fatalf("%s on a transient chunk-load failure = %d, want a server error, not a not-found status", tt.method, rec.Code)+ }+ if rec.Code < 500 {+ t.Errorf("%s on a transient chunk-load failure = %d, want a 5xx status", tt.method, rec.Code)+ }++ store.listErr = nil+ if _, err := store.FindEntry(context.Background(), util.FullPath(fs.tusSessionInfoPath(tusTestUploadID))); err != nil {+ t.Errorf("session removed after a transient %s failure: %v", tt.method, err)+ }+ })+ }+}++// TestFilerServer_tusHandler_ChunkLoadNotFoundStillNotFound verifies a chunk+// listing failure that genuinely means "not found" is still reported as such,+// so the fix for #11151 does not mask a real absence.+func TestFilerServer_tusHandler_ChunkLoadNotFoundStillNotFound(t *testing.T) {+ fs, store := newTusTestServer(t, map[string]string{tusTestUploadID: "/buckets/data/file.bin"})+ store.listErr = filer_pb.ErrNotFound++ req := tusRequest(http.MethodHead, "/.tus/.uploads/"+tusTestUploadID, map[string]string{+ "Authorization": "Bearer " + signFilerToken(t, tusTestReadKey, nil, nil),+ }, "")+ rec := httptest.NewRecorder()+ fs.tusHandler(rec, req)++ if rec.Code != http.StatusNotFound {+ t.Fatalf("HEAD on a genuinely missing session = %d, want %d", rec.Code, http.StatusNotFound)+ }++ deleteReq := tusRequest(http.MethodDelete, "/.tus/.uploads/"+tusTestUploadID, map[string]string{+ "Authorization": "Bearer " + signFilerToken(t, tusTestWriteKey, nil, nil),+ }, "")+ deleteRec := httptest.NewRecorder()+ fs.tusHandler(deleteRec, deleteReq)++ if deleteRec.Code != http.StatusNoContent {+ t.Fatalf("DELETE on a genuinely missing session = %d, want %d", deleteRec.Code, http.StatusNoContent)+ }+}