Skip to content

Await chained key computation in AsyncEnumerable ordering - #135356

Merged
eiriktsarpalis merged 2 commits into
mainfrom
copilot/fix-nullreferenceexception-thenby
Oct 12, 2026
Merged

eiriktsarpalis merged 2 commits into
mainfrom
copilot/fix-nullreferenceexception-thenby

Conversation

Copilot AI commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

ThenBy and ThenByDescending discard chained key-computation tasks, allowing sorting to read uninitialized keys when selectors suspend and silently ignoring selector exceptions.

  • Fix: Await each subsequent sorter’s key computation before sorting.
  • Regression coverage: Add deterministic suspended-selector cases for secondary and third-level ordering in both directions, plus exception propagation when primary keys differ.
if (_next is not null)
{
    await _next.ComputeKeysAsync(elements, count, cancellationToken);
}

@azure-pipelines

azure-pipelines Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix NullReferenceException in async ThenBy key selector Await chained key computation in AsyncEnumerable ordering Oct 7, 2026
Copilot AI requested a review from eiriktsarpalis October 7, 2026 18:22
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-linq
See info in area-owners.md if you want to be subscribed.

@eiriktsarpalis

Copy link
Copy Markdown
Member

/ba-g test failure is unrelated.

@eiriktsarpalis
eiriktsarpalis merged commit 1bde9a5 into main Oct 12, 2026
90 of 92 checks passed
@eiriktsarpalis
eiriktsarpalis deleted the copilot/fix-nullreferenceexception-thenby branch October 12, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsyncEnumerable.ThenBy with async key selector throws NullReferenceException: secondary keys not awaited

4 participants