kv-store-entry create --dir never closes uploaded files and retries with an empty body
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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時間
- マージ済み PR(30日)
- 23
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 件 ·
メンテナーはふだん 1 日以内に返信
-
feature request
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
status:needs-review type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Gentleman-Programming/engram#2079 ·
メンテナーはふだん 1 日以内に返信
-
bug triage/pending
難易度 1/5 1時間未満 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
limitlessprojects/Go-Hybrid#1377 ·
メンテナーはふだん 1 日以内に返信
-
bug report
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 3 日以内に返信