Conversation
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.
Problem
Cross-DC downloads (files whose
dc_iddiffers from the account main DC) hang forever.tg downloadcreates a 0-byte output file, sends oneupload.getFile, and never completes.Root cause is the known gotd/td#1341 deadlock: the floodwait
Waiterscheduler runs a single send-loop goroutine, and when a download triggers the serverFILE_MIGRATE_Nflow it re-enters the middleware with nestedauth.exportAuthorization/upload.getFilecalls. Those nested calls are queued behind the very same send loop that is busy inside the download, so they are never sent and the invoke waits forever.Fix
Use
floodwait.SimpleWaiter(same package ingotd/contrib, already pinned atgithub.com/gotd/contrib v0.24.0) instead of the scheduler-basedWaiter.SimpleWaitersleeps inline on flood-wait errors and never re-enters a scheduler, which is exactly the scenario the maintainers recommended in gotd/td#1341 comments ("i've just moved to SimpleWaiter", "disable floodwaiter and there are no more problems with downloads"). The CLI is a one-off command-line tool, which matches SimpleWaiter's documented use case.SimpleWaiterimplements the sametelegram.Middlewarecontract, so only two call sites change: the middleware construction and theconnectWithwrapper (SimpleWaiter has noRun, so the wrapper is dropped).Verification
Built locally and verified with a real account:
tg download @ulptxtlog1 904(file on a non-main DC, 34.4 MB): previously hung forever, now completes — 36,078,229 bytes, sha256 identical to the same file fetched through Telegram Web.tg download @ulptxtlog1 880(older file, 21,064,572 bytes): completes, size matches the document metadata exactly.go test ./...: all tests pass.gofmt -l cmd/tg/app.go: clean.Fixes the
tg downloadhang tracked by gotd/td#1341.