GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||
GeezerVison is showing github.com — fix: eliminate rebalancer waiter timeout race by ReubenBond · Pull Request #10311 · dotnet/orleans Conversation
|
| File | Description |
|---|---|
| test/TestInfrastructure/TestExtensions/Diagnostics/RebalancerDiagnosticObserver.cs | Reworks waiter lifecycle/timeout handling to avoid continuation-vs-timeout races. |
| test/Orleans.Core.Tests/Diagnostics/DiagnosticInfrastructureRegressionTests.cs | Updates and adds tests to validate the fixed waiter/timeout behavior and synchronous completion. |
test/Orleans.Core.Tests/Diagnostics/DiagnosticInfrastructureRegressionTests.cs:98
var waitTask = observer.WaitForSessionStopAsync();
test/Orleans.Core.Tests/Diagnostics/DiagnosticInfrastructureRegressionTests.cs:117
var waitTask = observer.WaitForSessionStopAsync();
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Complete diagnostic observer waiters directly while holding the waiter lock so synchronous event delivery cannot lose to a delayed timeout continuation. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 0c7d7f36-28fd-45f3-aeaf-218a5979a0d7
Install timeout timers before scheduling them so zero-duration timeouts cannot fire before the waiter owns and can dispose the timer. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 0c7d7f36-28fd-45f3-aeaf-218a5979a0d7
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
test/TestInfrastructure/TestExtensions/Diagnostics/RebalancerDiagnosticObserver.cs:254
WaitForEventAsync always creates a timer-based timeout even when timeout is TimeSpan.Zero/negative, which means the returned task only faults once a ThreadPool timer callback runs. For an immediate timeout (and to keep tests deterministic under threadpool starvation), return a faulted task directly when timeout <= TimeSpan.Zero. lock (_waitersLock)
{
var waiter = new EventWaiter<TEvent>(predicate);
_waiters.Add(waiter);
waiter.StartTimeout(timeout, () => TimeoutWaiter(waiter, timeoutMessage));
test/Orleans.Core.Tests/Diagnostics/DiagnosticInfrastructureRegressionTests.cs:79
WaitForCycleAsync()), which can make failures hang for a long time. Keeping an explicit short timeout preserves fast failure while still validating synchronous completion via IsCompletedSuccessfully. var waitTask = observer.WaitForCycleAsync();
test/Orleans.Core.Tests/Diagnostics/DiagnosticInfrastructureRegressionTests.cs:98
WaitForSessionStopAsync()), which can make failures hang for a long time. Prefer an explicit short timeout to keep failures quick and deterministic. var waitTask = observer.WaitForSessionStopAsync();
test/TestInfrastructure/TestExtensions/Diagnostics/RebalancerDiagnosticObserver.cs:236
WaitUntilAsync currently always registers a waiter + timer even when timeout is TimeSpan.Zero/negative. That relies on a ThreadPool timer callback to fault the task, which can be delayed under load (the exact flakiness this helper is trying to avoid). Consider treating non-positive timeouts as an immediate timeout by returning a faulted task without enqueuing a waiter.This issue also appears on line 250 of the same file.
if (predicate())
{
return Task.CompletedTask;
}
Sorry, something went wrong.
There was an error while loading. Please reload this page.
463052c to
49667e5
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
test/Orleans.Core.Tests/Diagnostics/DiagnosticInfrastructureRegressionTests.cs:120
var waitTask = observer.WaitForSessionStopAsync();
ActivationRebalancerEvents.EmitSessionStop(siloAddress, "latest", 1);
Assert.True(waitTask.IsCompletedSuccessfully);
test/Orleans.Core.Tests/Diagnostics/DiagnosticInfrastructureRegressionTests.cs:83
var waitTask = observer.WaitForCycleAsync();
Assert.False(waitTask.IsCompleted);
ActivationRebalancerEvents.EmitCycleStop(siloAddress, 2, 2, 0.2, TimeSpan.FromMilliseconds(1), false);
Assert.True(waitTask.IsCompletedSuccessfully);
test/Orleans.Core.Tests/Diagnostics/DiagnosticInfrastructureRegressionTests.cs:102
var waitTask = observer.WaitForSessionStopAsync();
Assert.False(waitTask.IsCompleted);
ActivationRebalancerEvents.EmitSessionStop(siloAddress, "latest", 2);
Assert.True(waitTask.IsCompletedSuccessfully);
test/TestInfrastructure/TestExtensions/Diagnostics/RebalancerDiagnosticObserver.cs:322
Timer, disposing the observer while there are outstanding waiters can leave timers running and callbacks firing after disposal (potentially affecting later tests and keeping the observer rooted longer than necessary). It would be safer to fail/clear any outstanding waiters and dispose their timers when RebalancerDiagnosticObserver is disposed. public void Dispose()
{
_subscription?.Dispose();
}
test/TestInfrastructure/TestExtensions/Diagnostics/RebalancerDiagnosticObserver.cs:256
WaitFor...Async(TimeSpan.Zero) now relies on a thread-pool Timer firing to fault the waiter. Under thread-pool starvation (the same kind of CI load this helper is meant to harden against), the timer callback can be delayed, causing a supposed immediate timeout to take arbitrarily long (or hang the test until the framework timeout). Consider handling TimeSpan.Zero synchronously while holding _waitersLock so the returned task is faulted immediately without requiring a timer callback. private Task WaitUntilAsync(Func<bool> predicate, TimeSpan timeout, Func<string> timeoutMessage)
{
lock (_waitersLock)
{
if (predicate())
{
return Task.CompletedTask;
}
var waiter = new ConditionWaiter(predicate);
_waiters.Add(waiter);
waiter.StartTimeout(timeout, () => TimeoutWaiter(waiter, timeoutMessage));
return waiter.Task;
}
}
private Task<TEvent> WaitForEventAsync<TEvent>(
Func<TEvent, bool> predicate,
TimeSpan timeout,
Func<string> timeoutMessage)
where TEvent : ActivationRebalancerEvents.RebalancerEvent
{
lock (_waitersLock)
{
var waiter = new EventWaiter<TEvent>(predicate);
_waiters.Add(waiter);
waiter.StartTimeout(timeout, () => TimeoutWaiter(waiter, timeoutMessage));
return waiter.Task;
}
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.