Repository navigation
[patch] Run queued Invoke/InvokeAsync work on the default scheduler, so it stays on the owner thread - #74
Merged
Conversation
…so it stays on the owner thread DoInvokes called task.RunSynchronously() with no scheduler, which targets TaskScheduler.Current. When DoInvokes is itself called from a task on a scheduler that refuses to inline, the queued task went back to that scheduler, so the delegate ran off the owner thread or, on a single-thread scheduler, deadlocked. RunSynchronously(TaskScheduler.Default) always inlines here. Fixes #65 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bm33TiYrofqKs4oGc3UGUU
|
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 #65
Problem
DoInvokesdrainedTaskQueuewithtask.RunSynchronously(), which targetsTaskScheduler.Current. SupposeDoInvokesis itself called from a task on a scheduler whoseTryExecuteTaskInlinereturnsfalse. The queued task then went back to that scheduler, with two possible outcomes:Invoked delegate ran on another thread, which breaks the library's core guarantee.Change
task.RunSynchronously(TaskScheduler.Default). The default scheduler always inlines here, so the delegate runs on the owner thread. A comment explains why the argument matters.Tests
New
DoInvokesFromATaskOnANonInliningSchedulerRunsInvokeOnTheOwnerThreadinInvokerTests:NonInliningTaskSchedulerqueues to the thread pool and refuses to inline. The owner loop runs as a task on it.Invoke, and the owner callsDoInvokes.DoInvokesreturns within a 10 s bound, and that the delegate ran on the owner's thread.Checked locally (Linux, net10.0):
#71 also edits the
TaskQueuedrain loop inDoInvokes, so whichever lands second will need a one-line merge.🤖 Generated with Claude Code
https://claude.ai/code/session_01Bm33TiYrofqKs4oGc3UGUU
Generated by Claude Code