Skip to content

Possible bug in pull request #18451 #18972

Closed
@melnikov77

Description

@melnikov77

Describe the bug

New Write/WriteLine/WriteAsync/WriteLineAsync ReadOnlySpan/ReadOnlyMemory overloads
in HttpResponseStreamWriter.cs will not write all data if the data exceeds internal buffer.

See code from pull request (#18451) with my comments:

    public override void Write(ReadOnlySpan<char> value)
    {
        if (_disposed)
        {
            throw new ObjectDisposedException(nameof(HttpResponseStreamWriter));
        }
        var written = 0;
        while (written < value.Length)
        {
            if (_charBufferCount == _charBufferSize)
            {
                FlushInternal(flushEncoder: false);
            }


            written = CopyToCharBuffer(value);


            if (written < value.Length)
            {
               value = value.Slice(written);
               // if "written" >= value.Length 
               // then we will exit loop and last chunk will not be copied
               // to fix this we should reset "written" after each Slice
            }
        };
 }

The same problem exists in WriteAsyncAwaited(ReadOnlyMemory value)

To Reproduce

Further technical details

  • ASP.NET Core version

Metadata

Metadata

Assignees

Labels

area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions