RNTBD Dispatcher: Fixes idle timer thread pool starvation (#4393)#5817
Open
NaluTripician wants to merge 4 commits intomsdata/directfrom
Open
RNTBD Dispatcher: Fixes idle timer thread pool starvation (#4393)#5817NaluTripician wants to merge 4 commits intomsdata/directfrom
NaluTripician wants to merge 4 commits intomsdata/directfrom
Conversation
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. |
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4393.
Converts
Dispatcher.OnIdleTimerto async and wires it via.ContinueWith(...).Unwrap()so idle timer callbacks no longerblock thread-pool workers on
Task.Wait().Three-edit change to
Dispatcher.cs. Full validation, evidence, andhonest limitations in VALIDATION.md.
Marked draft because this branch is the staging copy; the
canonical fix will land in msdata/direct via a separate PR
informed by this validation work.
Validation summary
The fix (Dispatcher.cs, three edits):
OnIdleTimer→OnIdleTimerAsync(sync → asyncTask)WaitTaskAsyncalongside the still-present syncWaitTaskScheduleIdleTimerupdated to.ContinueWith(OnIdleTimerAsync, ...).Unwrap()with safety comment explaining why.Unwrap()is essential (without it the timer task completes early and disposal can race the still-running continuation)The omitted body of
OnIdleTimerAsyncis byte-for-byte identical to the pre-fixOnIdleTimerbody: lock blocks remain synchronous, noawaitinside any lock, and the existingDebug.Assert(!Monitor.IsEntered(...))guards oncallLockandconnectionLockare preserved.Why this bug is hard to test: The Dispatcher's idle timer arms with a 750-second minimum (
StoreClientFactory.cs600s floor +Connection.cs2*(sendHang+receiveHang)=150srace buffer). Production starvation requires sustained scale and timing conditions. This is why issue #4393 sat from 2024 to 2026 without a CI catch — single-client tests cannot reliably synthesize the production trigger.Evidence:
DispatcherIdleTimerFixTests(canonical evidence): usesInternalsVisibleTo+ reflection to exerciseWaitTaskAsyncandWaitTaskdirectly with aTaskCompletionSourcethat is never completed. Probe-based thread observation: async path yields the calling thread; sync path blocks it. 5/5 passing runs.RntbdIdleTimerStarvationTests(regression guard): asserts wiring stays intact (timersFired > 0via reflection-basedTraceListeneronDefaultTrace.TraceSource, observing the newTraceInformationline atOnIdleTimerAsyncentry) and thread delta stays bounded (< 10). Latency assertion was dropped because the ~1001ms ceiling observed across 6 clean runs is a probe-implementation artifact, not a Dispatcher signal..Wait()durations median 12.5s / mean 21.2s / p95 64.1s / max 67.6s, 67/110 calls blocked ≥1s. Six subsequent runs (3 at N=50, 3 at N=200) did not reproduce — bug is real in this environment but not reliably triggerable from a single test client at the scales we tested.What this PR does NOT do:
DisposeAsync/IAsyncDisposableChannel,ChannelDictionary,LoadBalancingChannel,LoadBalancingPartition,LbChannelState, orIChannelbool disposedtoint disposedor addInterlocked.CompareExchangeguardsWaitTask(preserved untouched in case other callers exist)Dispatcher.csplus one new unit test plus one reshaped integration test (and supporting Linux test-run scaffolding underscripts/)Limitations: