kopia/kopia · error

canceled when copying data

Error message

canceled when copying data

What it means

Cancellation guard in Uploader.copyWithProgress: u.IsCanceled() became true mid-copy (user interrupt, shutdown, or policy cancellation), so the upload loop stops immediately and reports errCanceled wrapped as 'canceled when copying data' instead of continuing a partial upload.

Solutions

  1. Detect cancellation with errors.Is on the canceled sentinel and re-run the snapshot when appropriate.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at snapshot/upload/upload.go:401 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of kopia/kopia@82495e54b5 (2026-09-07). Data as JSON: /api/errors/9840b00bd9889ef7. Report an issue: GitHub.

Appendix: source

Thrown at snapshot/upload/upload.go:401

	de.FileSize = written
	streamSize = written

	atomic.AddInt32(&u.stats.TotalFileCount, 1)
	atomic.AddInt64(&u.stats.TotalFileSize, de.FileSize)

	return de, nil
}

func (u *Uploader) copyWithProgress(dst io.Writer, src io.Reader) (int64, error) {
	uploadBuf := iocopy.GetBuffer()
	defer iocopy.ReleaseBuffer(uploadBuf)

	var written int64

	for {
		if u.IsCanceled() {
			return 0, errors.Wrap(errCanceled, "canceled when copying data")
		}

		readBytes, readErr := src.Read(uploadBuf)

		if readBytes > 0 {
			wroteBytes, writeErr := dst.Write(uploadBuf[0:readBytes])
			if wroteBytes > 0 {
				written += int64(wroteBytes)
				u.totalWrittenBytes.Add(int64(wroteBytes))
				u.Progress.HashedBytes(int64(wroteBytes))
			}

			if writeErr != nil {
				//nolint:wrapcheck
				return written, writeErr
			}

			if readBytes != wroteBytes {

View on GitHub (pinned to 82495e54b5)