From 79177e52f9b9eab94385e021e42a18f8aa9225cf Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Tue, 10 Feb 2026 23:51:08 +0000 Subject: [PATCH] Fix 100% CPU when EDIT_TIME=0 in image cleanup When EditDuration is zero or negative, cleanupTTL becomes zero, causing time.After(0) to fire immediately in a tight loop. Block on ctx.Done() instead when edit duration is disabled. Fixes #1991 --- backend/app/store/image/image.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/app/store/image/image.go b/backend/app/store/image/image.go index 6339d8e1..2bfea93b 100644 --- a/backend/app/store/image/image.go +++ b/backend/app/store/image/image.go @@ -154,6 +154,12 @@ func (s *Service) ExtractNonProxiedPictures(commentHTML string) (ids []string) { // Cleanup runs periodic cleanup with 1.5*ServiceParams.EditDuration. Blocking loop, should be called inside of goroutine by consumer func (s *Service) Cleanup(ctx context.Context) { + if s.EditDuration <= 0 { + log.Printf("[INFO] pictures cleanup disabled, edit duration is %v", s.EditDuration) + <-ctx.Done() + return + } + cleanupTTL := s.EditDuration * 15 / 10 // cleanup images older than 1.5 * EditDuration log.Printf("[INFO] start pictures cleanup, staging ttl=%v", cleanupTTL)