From b26866fe0cc90ca282372e99569276eca47e2f30 Mon Sep 17 00:00:00 2001 From: Max Ignatenko Date: Thu, 14 Nov 2024 12:34:13 +0000 Subject: [PATCH] fix: update lastSuccessTimestamp after each request too Updating only in run() can be delayed arbitrarily long under load. --- cmd/plc-mirror/mirror.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/plc-mirror/mirror.go b/cmd/plc-mirror/mirror.go index 489b2a6..808de96 100644 --- a/cmd/plc-mirror/mirror.go +++ b/cmd/plc-mirror/mirror.go @@ -201,11 +201,12 @@ func (m *Mirror) runOnce(ctx context.Context) error { return fmt.Errorf("inserting log entry into database: %w", err) } + m.mu.Lock() + m.lastSuccessTimestamp = time.Now() if !lastTimestamp.IsZero() { - m.mu.Lock() m.lastRecordTimestamp = lastTimestamp - m.mu.Unlock() } + m.mu.Unlock() log.Info().Msgf("Got %d log entries. New cursor: %q", len(newEntries), cursor) }