CCOR-13153 - blocking/async void hot path causes excessive task-update latency#150
Draft
chrishagglund-ship-it wants to merge 4 commits into
Draft
CCOR-13153 - blocking/async void hot path causes excessive task-update latency#150chrishagglund-ship-it wants to merge 4 commits into
chrishagglund-ship-it wants to merge 4 commits into
Conversation
Contributor
Author
|
I might want to reduce this to just the first commit since the 2nd commit is more of a "fix this across the board" type of thing |
…ake-async stuff has a much broader scope
652e0e8 to
28bea21
Compare
…d signatures to match async Task implementations
…onsistency to happen
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.
Thread starvation and broken async patterns (
async void)This is the core latency problem. The worker's hot path —
WorkOnce,ProcessTasks,ProcessTask— were all declaredasync voidinstead ofasync Task. In C#,async voidmethods are fire-and-forget: the caller has no way toawaitthem, and any exception after the firstawaitbecomes an unobserved thread-pool exception. The consequences were:WorkOncereturnedvoidand couldn't be awaited. TheRunningWorkerDone()monitor count drifted from reality.Thread.Sleepwas used everywhere (poll interval, error backoff, retry backoff), which blocks thread-pool threads instead of releasing them. Under load, this could starve the thread pool — the very thing that async/await exists to prevent.PollTaskandUpdateTaskAPI calls inTaskResourceApiwere fake-async — they wrapped synchronous HTTP calls inTask.FromResult(...), so even the nominal async path blocked a thread.The fix converts all
async voidtoasync Task, replaces allThread.Sleepwithawait Task.Delay, and introduces truly asyncPollTaskAsync/UpdateTaskAsync/CallApiAsyncmethods that useRestClient.ExecuteAsyncend-to-end.Miscellaneous bugs
ProcessTask'sfinallyblock, the condition was== CancellationToken.Noneinstead of!=, meaning the cancellation token was never checked when an actual token was provided.OperationCanceledExceptionwas caught in the worker loop, it slept 10ms and re-enteredwhile(true), immediately re-throwing — creating an infinite tight loop on shutdown. Now it cleanlybreaks out of the loop.RecordUncaughtException()lost the exception type: It was a bare counter increment with no labels, so you couldn't tell what kind of exception was occurring.