gotd: fix infinite loop if server keeps replying with timeout to download request

This commit is contained in:
Tulir Asokan
2026-03-28 16:32:37 +02:00
parent bec7ee8f5e
commit 472b9df44c

View File

@@ -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")