Skip to content

fix: retry stream read errors in SimpleDownloader#432

Open
agoncharov-reef wants to merge 3 commits into
masterfrom
retry-on-mid-stream-read-errors
Open

fix: retry stream read errors in SimpleDownloader#432
agoncharov-reef wants to merge 3 commits into
masterfrom
retry-on-mid-stream-read-errors

Conversation

@agoncharov-reef

@agoncharov-reef agoncharov-reef commented Jun 15, 2026

Copy link
Copy Markdown

SimpleDownloader already had range-based retry logic for truncated downloads (e.g. when the server closes the connection mid-stream), but ChunkedEncodingError and ContentDecodingError raised during iter_content bypassed that path and failed the download immediately.

This PR catches those exceptions during both the initial read and follow-up range requests, logs them at debug level, and lets the existing retry loop resume from response.raw.tell().

@kacper-wolkiewicz-reef kacper-wolkiewicz-reef left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some doubts worth checking I think?

Comment thread b2sdk/_internal/transfer/inbound/downloader/simple.py Outdated
Comment thread b2sdk/_internal/transfer/inbound/downloader/simple.py
logger.debug('Stream read error during download, will retry if needed: %s', exc)
bytes_read += followup_response.raw.tell()
retries_left -= 1
return bytes_read, digest.hexdigest()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not intuitive to me that we return here without an error in case all retries are exhausted. Especially that in some cases validation of the downloaded file is skipped.

digest.update(data)
decoded_bytes_read += len(data)
except (ChunkedEncodingError, ContentDecodingError) as exc:
logger.debug('Stream read error during download, will retry if needed: %s', exc)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be some wait time before the next try?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants