client: addFile closes the source file before io.Copy — multipart file uploads always fail
Nobody has claimed this yet.
- Dominant language
- Shell
- Stars
- 33
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
In client.go (current master, v1.22.66), addFile closes the opened file before calling io.Copy(part, file):
file, err := os.Open(filepath.Clean(path))
if err != nil {
return err
}
err = file.Close() // closes here...
...
_, err = io.Copy(part, file) // ...then reads from a closed file
Any multipart form-file upload prepared through this helper fails with file already closed.
Repro (Go 1.26):
// addFile(w, "file", tmpfile) always returns:
// read <tmpfile>: file already closed
Fix: close the file only after the copy (defer). I have a fix + regression test ready and will open a PR linked to this issue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in client.go at the addFile helper and reproduce the multipart upload failure described in the issue. Add or run a regression test for a temporary file upload; done means io.Copy can read the source successfully and the upload no longer returns “file already closed”.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100