Skip to content

Add configurable SSE parser buffer limit - #132275

Draft
mrek-msft with Copilot wants to merge 2 commits into
mainfrom
copilot/add-sseparser-options
Draft

Add configurable SSE parser buffer limit#132275
mrek-msft with Copilot wants to merge 2 commits into
mainfrom
copilot/add-sseparser-options

Conversation

Copilot AI commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

SSE parsing now supports a caller-configured buffer limit through SseParserOptions<T>.

API

  • Adds SseParserOptions<T> with ItemParser and MaxBufferSize.
  • Sets MaxBufferSize to -1 by default, preserving the internal default limit.
  • Uses the options-based SseParser.Create overload as the parser creation path.
var parser = SseParser.Create(stream, new SseParserOptions<string>(
    static (_, bytes) => Encoding.UTF8.GetString(bytes))
{
    MaxBufferSize = 1024 * 1024
});

Coverage

  • Replaces reflection-based buffer-limit test setup with the public API.
  • Updates parser and formatter tests for the options-based construction path.

Note

This description was generated by GitHub Copilot.

Copilot AI lite review requested due to automatic review settings August 13, 2026 13:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
16 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: mrek-msft <188900745+mrek-msft@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 13, 2026 13:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Suppressed comments (2)

src/libraries/System.Net.ServerSentEvents/src/System/Net/ServerSentEvents/SseParserOptions.cs:28

  • SseParserOptions<T>.MaxBufferSize is documented as "-1 to use the default limit", but values < -1 currently flow through and (because of the _maxBufferSize >= 0 guard) effectively disable the limit. It would be safer to validate that MaxBufferSize is either -1 or >= 0 and throw ArgumentOutOfRangeException otherwise.
        /// <summary>Gets the parser to use to transform each payload of bytes into a data element.</summary>
        public SseItemParser<T> ItemParser { get; }

        /// <summary>Gets or sets the maximum buffer size, or -1 to use the default limit.</summary>
        public int MaxBufferSize { get; set; } = -1;

src/libraries/System.Net.ServerSentEvents/tests/SseParserTests.cs:34

  • There’s no test coverage for invalid MaxBufferSize values (e.g., < -1). Adding a focused test would ensure the new option can’t be used to silently disable buffer limiting via negative values.
        [Fact]
        public void Options_DefaultMaxBufferSize()
        {
            var options = new SseParserOptions<string>(delegate { return ""; });

            Assert.Equal(-1, options.MaxBufferSize);
        }

Comment on lines 15 to +19
/// <param name="sseStream">The stream containing the data to parse.</param>
/// <param name="itemParser">The parser to use to transform each payload of bytes into a data element.</param>
/// <param name="options">The options to use when parsing the stream.</param>
/// <returns>The enumerable, which can be enumerated synchronously or asynchronously.</returns>
/// <exception cref="ArgumentNullException"><paramref name="sseStream"/> or <paramref name="itemParser"/> is null.</exception>
public static SseParser<T> Create<T>(Stream sseStream, SseItemParser<T> itemParser)
/// <exception cref="ArgumentNullException"><paramref name="sseStream"/> or <paramref name="options"/> is null.</exception>
public static SseParser<T> Create<T>(Stream sseStream, SseParserOptions<T> options)
Comment on lines 26 to +30
public static partial class SseParser
{
public const string EventTypeDefault = "message";
public static System.Net.ServerSentEvents.SseParser<string> Create(System.IO.Stream sseStream) { throw null; }
public static System.Net.ServerSentEvents.SseParser<T> Create<T>(System.IO.Stream sseStream, System.Net.ServerSentEvents.SseItemParser<T> itemParser) { throw null; }
public static System.Net.ServerSentEvents.SseParser<T> Create<T>(System.IO.Stream sseStream, System.Net.ServerSentEvents.SseParserOptions<T> options) { throw null; }
}
Copilot AI changed the title [WIP] Add option to limit SseParser's internal buffer size Add configurable SSE parser buffer limit Aug 13, 2026
Copilot AI requested a review from mrek-msft August 13, 2026 14:00
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Option to limit SseParser's internal buffer size

4 participants