kv-store-entry create --dir never closes uploaded files and retries with an empty body
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with ProcessDir in pkg/commands/kvstoreentry/create.go and trace how the opened file is passed through fastly.FileLengthReader into the upload and retry. The issue describes two regression checks against the mock API: verify the file is closed after the command returns, and verify a retry sends the full FOO\n body. Done when both checks pass.
由索引模型根据 Issue 内容生成。
描述
What happens
fastly kv-store-entry create --store-id <id> --dir <path> opens every file in the directory with os.Open in ProcessDir (pkg/commands/kvstoreentry/create.go) and never closes it. The file is wrapped in fastly.FileLengthReader, which is not an io.Closer, so the HTTP client does not close it either. Each upload keeps its descriptor open until the garbage collector happens to finalize the *os.File. On a large directory this can run into the per process open file limit (256 by default on macOS).
The same goroutine retries the upload once when the error contains net/http: cannot rewind body after connection loss. The retry passes the same reader again, but the failed attempt has already read from the file, so the retry sends a short or empty body while the request still declares the full length. The retry cannot succeed.
What should happen
Each file should be closed once its upload is done, and the file should be rewound to the start before the retry so the full content is sent again.
Minimal repro
Two tests against the mock API show both problems:
- Capture
InsertKVStoreKeyInput.BodyinInsertKVStoreKeyFn, runkv-store-entry create --store-id x --dir testdata/example, then read from the captured body after the command returns. The read returnsEOFinstead ofos.ErrClosed, so the file is still open. - Make the first
InsertKVStoreKeyFncall read the body and returnerrors.New("net/http: cannot rewind body after connection loss"), and make the second call check the body. The second call receives""instead of the file content"FOO\n".
Root cause
ProcessDir has no f.Close() for the file it opens, and the retry branch calls insertKey(opts) again without seeking the file back to offset 0.
I have a fix with a regression test ready and can open a PR if you assign this to me.
- 主要语言
- Go
- 星标
- 164
- 派生
- 81
- 平均合并
- 1 天 3 小时
- 30 天内合并 PR
- 23
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fastly/cli 的其他 Issue
-
bug feature request
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
feature request
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
feature request
难度 3/5 1-2 天 新手友好度 52/100
维护者通常 1 天内回复
-
feature request
难度 4/5 3-5 天 新手友好度 38/100
fastly/cli#1790 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
feature request
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 1 天内回复
相似的 Issue
-
status:needs-review type:bug
难度 2/5 1-3 小时 新手友好度 78/100
Gentleman-Programming/engram#2079 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
limitlessprojects/Go-Hybrid#1377 ·
维护者通常 1 天内回复
-
bug report
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复