{"record":{"id":"41631a7a5325ece6","repo":"juicedata/juicefs","slug":"size-of-first-key-shold-be-5-but-got-v","errorCode":null,"errorMessage":"size of first key shold be 5, but got %v","messagePattern":"size of first key shold be 5, but got (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/objbench.go","lineNumber":905,"sourceCode":"\t\t}\n\t\tdefer blob.Delete(ctx, key) //nolint:errcheck\n\t\tif isFileSystem {\n\t\t\tobjs, err := listAll(ctx, blob, \"\", \"\", 2)\n\t\t\tif err == nil {\n\t\t\t\tif len(objs) != 2 {\n\t\t\t\t\treturn fmt.Errorf(\"list should return 2 keys, but got %d\", len(objs))\n\t\t\t\t}\n\t\t\t\tif objs[0].Key() != \"\" {\n\t\t\t\t\treturn fmt.Errorf(\"first key should be empty string, but got %s\", objs[0].Key())\n\t\t\t\t}\n\t\t\t\tif objs[0].Size() != 0 {\n\t\t\t\t\treturn fmt.Errorf(\"first object size should be 0, but got %d\", objs[0].Size())\n\t\t\t\t}\n\t\t\t\tif objs[1].Key() != key {\n\t\t\t\t\treturn fmt.Errorf(\"first key should be test, but got %s\", objs[1].Key())\n\t\t\t\t}\n\t\t\t\tif objs[1].Size() != 5 {\n\t\t\t\t\treturn fmt.Errorf(\"size of first key shold be 5, but got %v\", objs[1].Size())\n\t\t\t\t}\n\t\t\t\tnow := time.Now()\n\t\t\t\tif objs[1].Mtime().Before(now.Add(-30*time.Second)) || objs[1].Mtime().After(now.Add(time.Second*30)) {\n\t\t\t\t\treturn fmt.Errorf(\"mtime of key should be within 30 seconds, but got %s\", objs[1].Mtime().Sub(now))\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn fmt.Errorf(\"list failed: %s\", err)\n\t\t\t}\n\n\t\t\tobjs, err = listAll(ctx, blob, \"\", \"test2\", 1)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"list failed: %s\", err)\n\t\t\t} else if len(objs) != 0 {\n\t\t\t\treturn fmt.Errorf(\"list should not return anything, but got %d\", len(objs))\n\t\t\t}\n\t\t} else {\n\t\t\tobjs, err2 := listAll(ctx, blob, \"\", \"\", 1)\n\t\t\tif err2 == nil {","sourceCodeStart":887,"sourceCodeEnd":923,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/cmd/objbench.go#L887-L923","documentation":"Raised in the objbench 'list objects' filesystem case: the second listed entry is the just-uploaded 5-byte object 'test', so its Size() must be 5, but the backend reported a different size. This asserts that listing returns accurate object sizes (typo 'shold' is in the source message).","triggerScenarios":"After Put of []byte(\"hello\"), listAll returns the key correctly but objs[1].Size() != 5 — e.g. the backend reports the directory stat size, a block-aligned size, 0, or a stale cached size.","commonSituations":"Custom file backend using os.Stat's Size() on a directory or returning allocated size; a backend whose List fills size from a stale cache; backends that don't populate size in list results at all; uploads still in flight/flushed asynchronously.","solutions":["Fix the backend's List to populate Size() from the file/object's actual length (5 for \"hello\").","Verify Put is fully flushed before List runs (no async write-behind reporting wrong sizes).","Compare with the reference file:// implementation in pkg/object.","Clear size/attr caches on the filesystem-backed store.","Rerun objbench to confirm."],"exampleFix":"// before\nreturn &entry{key: name, size: 0}, nil // size never populated\n// after\nfi, _ := os.Stat(path)\nreturn &entry{key: name, size: fi.Size()}, nil","handlingStrategy":"type-guard","validationCode":"objs, _ := listAll(ctx, blob, \"\", \"\", 2)\nif len(objs) > 1 && objs[1].Key() == key && objs[1].Size() != 5 {\n    log.Printf(\"reported size %d, want 5\", objs[1].Size())\n}","typeGuard":"func sizeMatches(o object.Object, want uint64) bool {\n    return o.Size() == want\n}","tryCatchPattern":"if s := objs[1].Size(); s != 5 {\n    log.Printf(\"list size %d != put size 5; check flush/caching\", s)\n}","preventionTips":["Populate Size() from actual object length in List.","Ensure Put completes (flush) before listing.","Avoid caching stale sizes in custom backends.","Validate with objbench after any List changes."],"tags":["object-storage","list","size","filesystem"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}