Repository navigation
Deny child attachment to the tasks Invoke queues [patch] - #93
Open
matt-edmondson wants to merge 1 commit into
Open
matt-edmondson wants to merge 1 commit into
matt-edmondson wants to merge 1 commit into
Conversation
The task built for an off-thread Invoke or InvokeAsync allowed children, so an AttachedToParent child started by the delegate attached to it. DoInvokes' RunSynchronously then blocked the owner's pump until the child finished, the caller waited too, and a faulted child surfaced as an AggregateException in place of the delegate's own result. On the owner thread the same call runs inline with nothing to attach to. The queued tasks now also set DenyChildAttach, as Task.Run does. Fixes #92 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW547mxaz1R4r27gAVm
|
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.



The tasks that an off-thread
Invoke/InvokeAsyncqueues were built withRunContinuationsAsynchronouslyonly. A child that the delegate started withAttachedToParenttherefore attached to them, which caused three problems:DoInvokescallsRunSynchronously, which waits for attached children. The owner thread's pump blocked until the child finished.AggregateExceptionwrapping the child's exception instead of the delegate's own result, which undoes Invoke() rethrows the inner exception withthrow ex.InnerException, discarding the stack trace of the code that actually failed #54/Keep the failing delegate's stack trace when Invoke rethrows #55.On the owner thread, the same call runs inline with no parent task, so none of this happens there.
Both queued tasks (the
Actionand theFunc<TReturn>paths, which every overload goes through) are now built withRunContinuationsAsynchronously | DenyChildAttach. This is the same reasonTask.RunsetsDenyChildAttach.One more finding while writing the tests: before this fix, the owner's
DoInvokesblocked for the child's whole lifetime, not just the caller. A child that waited on something the owner thread does next would deadlock the pump.Tests (new
AttachedChildTaskTests)Invoke(Action)andInvoke(Func<T>)from a worker thread return before a blocking attached child is released. A timer releases the child, not the owner thread, so the old behaviour can't deadlock the test. The children areLongRunning, so the blocked children can't starve the thread pool that the call's continuation needs.Invoke(Action)andInvokeAsync(Func<T>)from a worker don't throw an attached child's exception. The child still faults on its own.Fixes #92
Generated by Claude Code