ory / ory/client-go

client: addFile closes the source file before io.Copy — multipart file uploads always fail

Open Beginner friendly
#12 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.