Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 4202165

Browse files
authored
fix: Adjust big segments logic to prevent duplicate polls. (#225)
The contract tests attempt to determine that the SDK is not making redundant polls, and sometimes this test would fail. Theoretically this could also affect a server handling requests on many threads which concurrently request status before the first request has completed.
1 parent 6efa8d7 commit 4202165

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

pkgs/sdk/server/src/Internal/BigSegments/BigSegmentStoreWrapper.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal class BigSegmentStoreWrapper : IDisposable
2222
private readonly CancellationTokenSource _pollCanceller;
2323
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
2424
private readonly Logger _logger;
25+
private readonly Task<BigSegmentStoreStatus> _initialPoll;
2526

2627
private BigSegmentStoreStatus? _lastStatus;
2728

@@ -43,8 +44,9 @@ Logger logger
4344
_taskExecutor = taskExecutor;
4445
_logger = logger;
4546

47+
_initialPoll = Task.Run(PollStoreAndUpdateStatusAsync);
4648
_pollCanceller = taskExecutor.StartRepeatingTask(
47-
TimeSpan.Zero,
49+
config.StatusPollInterval,
4850
config.StatusPollInterval,
4951
PollStoreAndUpdateStatusAsync
5052
);
@@ -119,11 +121,7 @@ internal BigSegmentStoreStatus GetStatus()
119121
{
120122
_lock.ExitReadLock();
121123
}
122-
if (ret.HasValue)
123-
{
124-
return ret.Value;
125-
}
126-
return AsyncUtils.WaitSafely(() => PollStoreAndUpdateStatusAsync());
124+
return ret ?? _initialPoll.GetAwaiter().GetResult();
127125
}
128126

129127
private async Task<BigSegmentStoreStatus> PollStoreAndUpdateStatusAsync()

0 commit comments

Comments
 (0)