Repository navigation
Conversation
When Telegram can't serve a part (-503 Timeout after the retries, or its message is gone), the stream had already sent 206 and its headers, so the client got an empty body cut short and had to guess. rclone retried it as a short read over and over. - Read the first 64 KiB before writing the status line. If that fails, answer 502 (telegram_part_unavailable / telegram_read_failed) and log api.stream_unreadable. Errors with their own status (504 etc.) keep it. - The same for a part whose size is looked up on open (older uploads) and is gone: it was a 500. - The retry middleware returned a bare "context deadline exceeded" when the deadline ran out while it retried a -503, so the reason was lost. It now returns an error that reads as the Telegram error and still matches both (errors.Is deadline, tgerr.As). - Part errors name the message id.
bioidaika
added a commit
to bioidaika/teldrive
that referenced
this pull request
Nov 14, 2026
…rors - PR tgdrive#650: stream pre-reading returns 502 Bad Gateway instead of 206 when Telegram part is gone or unavailable before first byte - PR tgdrive#650: preserve Telegram RPC errors across retry deadline expirations - PR tgdrive#650: include message ID in download error logs - Issue tgdrive#651: add 'teldrive backfill-part-sizes' command to batch-resolve missing part sizes via Telegram into database
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some of my older files have a part Telegram won't serve any more: every chunk comes back as
-503 Timeout, or the message is gone. In 2.x the stream has already written206and the headers by then, so the client gets an empty body that just ends. rclone treats it as a short read and keeps retrying, and the log only sayscontext deadline exceeded.This PR:
502(telegram_part_unavailablefor a -503 or a missing message,telegram_read_failedotherwise) andapi.stream_unreadableis logged with the file id. Errors that already have their own status (504 etc.) keep it.rpc error code -503: Timeout (retried until the deadline)and still matcheserrors.Is(err, context.DeadlineExceeded)andtgerr.As.Normal streams only change in that the first 64 KiB are read before the headers go out.
Tested with unit tests for the stream handler and the retry middleware, and with
go test -race -tags=integrationfor api, telegramstore and transfer. I also tried it on a test instance by pointing a part at a message that doesn't exist: before it was a 500 (or an empty 206), now it's a 502 every time, and the file reads normally again once the part is fixed.