FailStage receives null exception when hub callback task is canceled#8064
Merged
Arkatufus merged 2 commits intoakkadotnet:devfrom Mar 4, 2026
Merged
Conversation
…eled In PartitionHub's consumer PreStart, the OnHubReady callback checked t.IsCanceled || t.IsFaulted but passed t.Exception to FailStage. When a task is canceled (not faulted), t.Exception is null per the Task contract. FailStage(null) causes downstream ports to complete normally instead of failing, silently swallowing the cancellation. Fix: align with BroadcastHub's consumer pattern by wrapping the task through Result.FromTask(), which already handles task cancellation correctly by calling t.GetAwaiter().GetResult() to produce the real TaskCanceledException from the runtime. Note: enabling #nullable in GraphStage.cs + Hub.cs catches this at compile time (CS8604 on the FailStage call). That flagged 6 call sites total, but only this one is a real bug — the other 5 already go through Result.FromTask. Enabling nullable in these files produces ~11 additional errors and is deferred to a separate effort.
Member
yeah @Arkatufus is gradually working on enabling nullability from the bottom up in the |
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.
Changes
In PartitionHub's consumer PreStart, the OnHubReady callback checked t.IsCanceled || t.IsFaulted but passed t.Exception to FailStage. When a task is canceled (not faulted), t.Exception is null.
I used Copilot to try to understand the implications of this issue. It said:
I'm confident that the task handling is incorrect, but I need someone who knows Streams to understand if there's user impact here or not.
In either case, I fixed it by copying BroadcastHub's consumer pattern by wrapping the task through Result.FromTask(), which already handles task cancellation correctly by calling t.GetAwaiter().GetResult() to produce the real TaskCanceledException from the runtime.
Note: enabling #nullable in GraphStage.cs + Hub.cs would catch this at compile time. That's a bigger change though, so will defer that work for the moment.
Checklist