Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

kv-store-entry create --dir never closes uploaded files and retries with an empty body

未关闭
#1,942 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
cli

调研方向

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:

  1. Capture InsertKVStoreKeyInput.Body in InsertKVStoreKeyFn, run kv-store-entry create --store-id x --dir testdata/example, then read from the captured body after the command returns. The read returns EOF instead of os.ErrClosed, so the file is still open.
  2. Make the first InsertKVStoreKeyFn call read the body and return errors.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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

fastly/cli 的其他 Issue

查看 fastly/cli 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。