You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(b2): Writer.ReadFrom returns context.Canceled instead of the upload error #245
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:
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.
Activity