From 472b9df44c98780bee0f54f68bc4736cc05af7f9 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 28 Mar 2026 16:32:37 +0200 Subject: [PATCH] gotd: fix infinite loop if server keeps replying with timeout to download request --- pkg/gotd/telegram/downloader/reader.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/gotd/telegram/downloader/reader.go b/pkg/gotd/telegram/downloader/reader.go index 3d200bfa..4151606c 100644 --- a/pkg/gotd/telegram/downloader/reader.go +++ b/pkg/gotd/telegram/downloader/reader.go @@ -88,11 +88,13 @@ func (r *reader) nextPlain(ctx context.Context) (block, error) { } func (r *reader) next(ctx context.Context, offset int64, limit int) (block, error) { + floodOrTimeoutRetries := 0 for { ch, err := r.sch.Chunk(ctx, offset, limit) if flood, err := tgerr.FloodWait(ctx, err); err != nil { - if flood || tgerr.Is(err, tg.ErrTimeout) { + if (flood || tgerr.Is(err, tg.ErrTimeout)) && floodOrTimeoutRetries < 10 { + floodOrTimeoutRetries++ continue } return block{}, errors.Wrap(err, "get next chunk")