Skip to content

fix(b2): Writer.ReadFrom returns context.Canceled instead of the upload error #245

Closed

Description

@ffumero2003

Problem

When a large-file upload fails permanently, io.Copy(w, r) into a *b2.Writer returns context canceled instead of the upload error.

io.Copy uses Writer.ReadFrom, which runs copyContext(w.ctx, w, r) (b2/writer.go, ReadFrom). When a part upload fails, Writer.setErr records the error and cancels w.ctx. copyContext then sees ctx.Done() and returns ctx.Err(), which is context.Canceled, so the real failure is masked. Writer.Close() still returns the recorded error, but a caller that checks io.Copy's error, as most code does, sees only the generic cancellation.

Reproduction

TestWriterReturnsError (b2/b2_test.go) injects a permanent uploadPart error and checks only err != nil. Tightened to errors.Is(err, want), it fails on current main:

io.Copy error = context canceled, want injected permanent upload failure

Expected

Writer.ReadFrom (and so io.Copy) returns the Writer's recorded error when the copy stops because the Writer failed, and returns the caller's context error only when the caller's own context was cancelled.

Acceptance criteria

  • TestWriterReturnsError asserts errors.Is(err, want) for the injected error, and it fails before the fix.
  • A test covers the caller's own cancellation: it still returns context.Canceled (or the deadline error).
  • Both ReadFrom paths (the seekable and the non-seekable reader) are covered.
  • Changelog entry under Fixed.

Notes

Activity

  1. added this to the 0.10.0 milestone on Oct 30, 2026
  2. self-assigned this
    on Oct 30, 2026
  3. added theissue type on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions