Skip to content

Stream fails when list contains fewer items than initialCount #8714

Closed

Description

@MikeBarker-MSFT

Product

Hot Chocolate

Version

15.1.7

Link to minimal reproduction

https://github.com/MikeBarker-MSFT/HotChocolateStreamMinimalRepro

Steps to reproduce

Use @stream with some initialCount to return items from a list where the list contains fewer items than the provided initialCount value.

What is expected?

The stream should return all items which are available.

What is actually happening?

The query fails and causes a null reference exception.

Relevant log output

Additional context

No response

Activity

  1. MikeBarker-MSFT commented on Sep 16, 2025

    @MikeBarker-MSFT
    ContributorAuthor

    I believe the issue is caused by these lines in ResolverTask.Execute.cs

    while (next)
    {
        count++;
        next = await enumerator.MoveNextAsync().ConfigureAwait(false);
        list.Add(enumerator.Current);
    
        if (count >= initialCount)
        {
            break;
        }
    }

    Here, the result of MoveNextAsync is not tested before calling list.Add(enumerator.Current), and because of this null (or, more correctly the default value) is placed in the list. When this is later read, it causes a NullReferenceException to be thrown.

  2. MikeBarker-MSFT commented on Sep 16, 2025

    @MikeBarker-MSFT
    ContributorAuthor

    I am going to pop up a PR with a proposed changeset.

  3. added 2 commits that reference this issue on Sep 17, 2025
    324039b
    3b80da6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions