Skip to content

fix(cli): switch to SimpleWaiter to unblock cross-DC downloads - #281

Open
vtxyer wants to merge 1 commit into
gotd:mainfrom
vtxyer:fix/simple-waiter-download
Open

vtxyer wants to merge 1 commit into
gotd:mainfrom
vtxyer:fix/simple-waiter-download

Conversation

@vtxyer

@vtxyer vtxyer commented Sep 30, 2026

Copy link
Copy Markdown

Problem

Cross-DC downloads (files whose dc_id differs from the account main DC) hang forever. tg download creates a 0-byte output file, sends one upload.getFile, and never completes.

Root cause is the known gotd/td#1341 deadlock: the floodwait Waiter scheduler runs a single send-loop goroutine, and when a download triggers the server FILE_MIGRATE_N flow it re-enters the middleware with nested auth.exportAuthorization/upload.getFile calls. 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 in gotd/contrib, already pinned at github.com/gotd/contrib v0.24.0) instead of the scheduler-based Waiter. SimpleWaiter sleeps 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.

SimpleWaiter implements the same telegram.Middleware contract, so only two call sites change: the middleware construction and the connectWith wrapper (SimpleWaiter has no Run, 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 download hang tracked by gotd/td#1341.

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.

1 participant