Skip to content

Commit 3c4e40c

Browse files
committed
fix: add 1s to context.WithTimeout
1 parent 38be0dc commit 3c4e40c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

waku/v2/api/history/cycle.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,10 @@ func (m *StorenodeCycle) SetStorenodeConfigProvider(provider StorenodeConfigProv
409409
m.storenodeConfigProvider = provider
410410
}
411411

412-
func (m *StorenodeCycle) WaitForAvailableStoreNode(ctx context.Context, timeout time.Duration) bool {
413-
// Add 1 second to timeout, because the storenode cycle has 1 second ticker, which doesn't tick on start.
412+
func (m *StorenodeCycle) WaitForAvailableStoreNode(ctx context.Context) bool {
413+
// Note: Add 1 second to timeout, because the storenode cycle has 1 second ticker, which doesn't tick on start.
414414
// This can be improved after merging https://github.com/status-im/status-go/pull/4380.
415415
// NOTE: https://stackoverflow.com/questions/32705582/how-to-get-time-tick-to-tick-immediately
416-
timeout += time.Second
417-
418-
ctx, cancel := context.WithTimeout(ctx, timeout)
419-
defer cancel()
420416

421417
wg := sync.WaitGroup{}
422418
wg.Add(1)
@@ -426,14 +422,30 @@ func (m *StorenodeCycle) WaitForAvailableStoreNode(ctx context.Context, timeout
426422
select {
427423
case <-m.StorenodeAvailableOneshotEmitter.Subscribe():
428424
case <-ctx.Done():
425+
if errors.Is(ctx.Err(), context.Canceled) {
426+
return
427+
}
428+
429+
// Wait for an additional second, but handle cancellation
430+
select {
431+
case <-time.After(1 * time.Second):
432+
case <-ctx.Done(): // context was cancelled
433+
}
434+
429435
return
436+
430437
}
431438
}
432439
}()
433440

434441
select {
435442
case <-waitForWaitGroup(&wg):
436443
case <-ctx.Done():
444+
// Wait for an additional second, but handle cancellation
445+
select {
446+
case <-time.After(1 * time.Second):
447+
case <-ctx.Done(): // context was cancelled o
448+
}
437449
}
438450

439451
return m.IsStorenodeAvailable(m.activeStorenode)

0 commit comments

Comments
 (0)