Repository navigation
ToChannel observes a failed read; simplifications - #307
Merged
Merged
Conversation
…ported as unobserved A failure in the read reaches the channel through Complete, as documented. The task that ran the read was dropped by every form that does not return the count (ToChannelReader, ToChannel, and ToChannel with an ignored out argument), so when the task was collected, TaskScheduler.UnobservedTaskException fired with the same failure. Produce now attaches an OnlyOnFaulted continuation that reads the task's Exception, as the Dataflow pump does, and still returns the original task: a caller who awaits the count sees the fault. Cost: one continuation per ToChannel call, nothing per row. Test: a failing read through the three forms that drop the count, then GC.Collect and WaitForPendingFinalizers, asserts that no unobserved exception names the read's failure. It fails before the change (three unobserved exceptions) and passes after. Release notes: one Fixed line under Changes since rc.16. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…er call Each change keeps the behavior; no public or protected signature changes. - The row reader's guard builds the wrapper exception with its constructor (a row-reading loop catches it) or calls the four-argument RowErrors.Create with row -1, so the three-argument Create and RowMappingFailure.Defer, which only existed to be found by reflection, are deleted. - The reader refusal of a captured run puts only the call that can throw inside the try. - The name check of a parameter list is three `case ... when` arms instead of three nested ifs, and the three-argument ResolveDerived, which had one caller, is deleted: that caller asks the four-argument one with `out _`. - GenericPool no longer repeats Take as an explicit interface member: the public Take already implements both interfaces. - The asynchronous void ExecuteTransactionAsync calls the conditional core directly instead of going through the generic overload, which wrapped the action a second time. The generic overload's async state machine and one wrapping lambda are gone per transaction. - ExecuteReaderAsync on an IDbCommand that is a DbCommand passes the handler with a delegate variance cast instead of a wrapping lambda. The cast makes the DbCommand overload the only applicable one, so it cannot pick itself. One closure and one delegate fewer per call. - DirectStream disposal sets the state with one Interlocked.Exchange instead of a compare-exchange loop; the timestamp the loop kept is only read while the state is Idle. Cost: nothing is added on any path; the two overload changes remove an allocation per call. Tests: ExecuteReaderAsync on a DbCommand held as IDbCommand calls the handler once for both return shapes (a wrong overload pick would recurse forever). Core tests and generator tests pass in Release; whole solution builds with 0 warnings. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
DeclaresNullPolicy no longer looks at fields: NullPolicy and NullValue cannot be put on a field, so a field never carried one in code that compiles. HasAttribute is one Any call. The generated text is byte-identical: the output of the generator tests (counters on and off) and of the generated benchmarks (net10.0 and net11.0) was compared before and after, file against file. Cost: none at run time; the generator runs at build time. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…refusal's try as it was - The unobserved-task test for ToChannel is its own class in the heap-measurement collection, which runs alone, so no parallel test raises the same text into its handler. It cannot pass vacuously: a faulted task it drops itself must be reported unobserved after the collection loop, and the task of the third form (held only through a weak reference) must be dead, before the list of the read's failures is asserted empty. Without the fix it still fails on that last assertion, with three unobserved exceptions. - ReaderRefusal builds the refusal's exception inside the try again, as before the simplification, so the set of exceptions turned into a refusal is unchanged. - Transaction.cs keeps its UTF-8 byte order mark, which the earlier commit dropped. - The ExecuteReaderAsync test is named for what it checks (one call per call), its comment says what the cast does, and the cast has a one-line comment; the two arguments behavior and cancellationToken are grouped on one line. - ModelReader lines are wrapped; a double blank line in DirectStream is removed. No behavior change; the generated text is still byte-identical to the base. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The two new assertions named Assert.IsAssignableFrom, which the xUnit analyzer reports (info); Assert.IsType with exactMatch false says the same. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
One bug fix, and simplifications from a look at the code added since rc.16. No public or protected signature changes (the
PublicAPIfiles are untouched) and the generated text is byte-identical.The bug
ToChannel.Producestarted the read as a task and, for the forms whose caller discards the count (ToChannelReader,ToChannel(...),out _), dropped it unobserved. A provider failure while reading then raisedTaskScheduler.UnobservedTaskExceptionwhen the task was finalized, in addition to completing the channel with the error.Producenow attaches anOnlyOnFaultedcontinuation that reads the task's exception, the way the Dataflow pump already does;readCountstays the original task, so a caller that awaits it still gets the exception. A Fixed: line is in the release notes.Test:
ToChannelUnobservedTests, overToChannelReader,ToChannelandToChannel(out _). Without the fix it fails on the last assertion withAssert.Empty() Failure: Collection was not empty, holding threeAggregateExceptions ("A Task's exception(s) were not observed ... The provider failed while reading."); with it the test passes. The test is serialized in the heap-measurement collection so no parallel test raises the same text into its handler, and it cannot pass vacuously: a faulted task the test drops itself must be reported unobserved, and the task of the third form (held only through a weak reference) must be dead, before the list is asserted empty.Simplifications
RowErrors.Createwith row -1, so the three-argumentCreateandRowMappingFailure.Defer, which only existed to be found by reflection, are deleted.try.case ... whenarms instead of three nestedifs; the three-argumentResolveDerived, which had one caller, is deleted.GenericPoolno longer repeatsTakeas an explicit interface member; the public one implements both.ExecuteTransactionAsynccalls the conditional core directly instead of going through the generic overload that wrapped the action a second time: one async state machine and one wrapping lambda fewer per transaction.ExecuteReaderAsyncon anIDbCommandthat is aDbCommandpasses the handler with a delegate variance cast instead of a wrapping lambda. The cast is an allocation saving, not a fix: the original lambda already bound theDbCommandoverload (the new test covers both call sites).DirectStreamdrops its loopingExchangehelper forInterlocked.Exchangeon dispose (the timestamp bits are read only while the state is idle, so dropping them in the terminal state is unobservable).DeclaresNullPolicyno longer looks at fields (the two attributes cannot be put on one), andHasAttributeis oneAnycall. Generated text is byte-identical: the generator tests' output (counters on and off) and the generated benchmarks (net10.0 and net11.0) were compared before and after, file against file.Left out
Three items overlap the wave of edits in #306 and are redone after it merges; one (a record struct for
Lease.Taken) was dropped because the netstandard targets have noIsExternalInit.Cost
Nothing per row. Per call: one wrapping lambda and one async state machine fewer on the transaction path, one closure fewer on
ExecuteReaderAsync; the bug fix adds one continuation perToChannelread.Reviews
Two Haiku lenses (correctness including the fix and the test; rules, tests and the release note) read the diff. Applied: the test serialized and guarded as above, the refusal's
tryrestored as before, byte order marks restored, argument grouping, a double blank line, and an xUnit analyzer note. Not applied: a release note for the variance cast (it fixes nothing).Checks: Release 16,153 and Debug 16,132 tests pass (16 skipped), 189 generator tests, 0 build warnings on every target framework, 267 sample checks,
dotnet formatstyle and analyzers clean on all 28 checks, DocFX 0 warnings, the style scan clean.🤖 Generated with Claude Code