From cb3958bac35dfa1958905dee3ca569df734c4373 Mon Sep 17 00:00:00 2001 From: erio Date: Wed, 4 Mar 2026 21:33:18 +0800 Subject: [PATCH] fix: use detached context for concurrency batch query to prevent all-zero display The upstream v0.1.90 changed GetAccountConcurrencyBatch from individual Lua script calls (which swallowed per-account errors) to a Redis pipeline approach that propagates errors from rdb.Time() or pipe.Exec(). When the HTTP request context is cancelled (e.g., browser abort), the entire batch fails and the handler silently shows all concurrency as 0. Fix: use context.WithTimeout(context.Background(), 3s) for the Redis call so HTTP request cancellation doesn't affect the read-only concurrency query. --- backend/internal/service/concurrency_service.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/internal/service/concurrency_service.go b/backend/internal/service/concurrency_service.go index 4dcf84e0..19d3d536 100644 --- a/backend/internal/service/concurrency_service.go +++ b/backend/internal/service/concurrency_service.go @@ -331,8 +331,9 @@ func (s *ConcurrencyService) StartSlotCleanupWorker(accountRepo AccountRepositor }() } -// GetAccountConcurrencyBatch gets current concurrency counts for multiple accounts -// Returns a map of accountID -> current concurrency count +// GetAccountConcurrencyBatch gets current concurrency counts for multiple accounts. +// Uses a detached context with timeout to prevent HTTP request cancellation from +// causing the entire batch to fail (which would show all concurrency as 0). func (s *ConcurrencyService) GetAccountConcurrencyBatch(ctx context.Context, accountIDs []int64) (map[int64]int, error) { if len(accountIDs) == 0 { return map[int64]int{}, nil @@ -344,5 +345,11 @@ func (s *ConcurrencyService) GetAccountConcurrencyBatch(ctx context.Context, acc } return result, nil } - return s.cache.GetAccountConcurrencyBatch(ctx, accountIDs) + + // Use a detached context so that a cancelled HTTP request doesn't cause + // the Redis pipeline to fail and return all-zero concurrency counts. + redisCtx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() + + return s.cache.GetAccountConcurrencyBatch(redisCtx, accountIDs) }