From 7af4ecc7196a1b74198ef7530291eded99be7baf Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Thu, 26 Sep 2024 10:01:05 -0600 Subject: [PATCH] backfill: fix stopTakeoutTimer Signed-off-by: Sumner Evans --- pkg/connector/backfill.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/connector/backfill.go b/pkg/connector/backfill.go index 985a32c1..5a33a098 100644 --- a/pkg/connector/backfill.go +++ b/pkg/connector/backfill.go @@ -162,7 +162,13 @@ func (t *TelegramClient) FetchMessages(ctx context.Context, fetchParams bridgev2 return nil, err } - defer t.stopTakeoutTimer.Reset(max(time.Hour, time.Duration(t.main.Bridge.Config.Backfill.Queue.BatchDelay*2))) + defer func() { + if t.stopTakeoutTimer == nil { + t.stopTakeoutTimer = time.AfterFunc(max(time.Hour, time.Duration(t.main.Bridge.Config.Backfill.Queue.BatchDelay*2)), sync.OnceFunc(func() { t.stopTakeout(ctx) })) + } else { + t.stopTakeoutTimer.Reset(max(time.Hour, time.Duration(t.main.Bridge.Config.Backfill.Queue.BatchDelay*2))) + } + }() } peer, err := t.inputPeerForPortalID(ctx, fetchParams.Portal.ID)