Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix corrupted streaming SSR output #50380

Merged
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ba6f214
Update sample to make issue easier to observe
SteveSandersonMS Aug 25, 2023
4d4fb58
Make ViewBufferTextWriter fail clearly if corrupt output will occur
SteveSandersonMS Aug 25, 2023
a62e540
Tiny cleanup
SteveSandersonMS Aug 25, 2023
5c91126
Add investigation notes as comments
SteveSandersonMS Aug 25, 2023
149be39
Temporary experiment with an alternative using MemoryStream
SteveSandersonMS Aug 28, 2023
7c9c9a7
Better implementation with paged pool
SteveSandersonMS Aug 28, 2023
4f6eaef
Cleaner implementation
SteveSandersonMS Aug 28, 2023
e3b1167
Optimizations for writing string or int
SteveSandersonMS Aug 28, 2023
fdd58c4
Split up code files
SteveSandersonMS Aug 28, 2023
000b02c
Add TextChunkTest
SteveSandersonMS Aug 28, 2023
6213043
Add TextChunkPageTest
SteveSandersonMS Aug 28, 2023
20c6156
Add TextChunkPagePoolTest
SteveSandersonMS Aug 28, 2023
e3831c6
Add TextChunkListBuilderTest
SteveSandersonMS Aug 28, 2023
00a1022
Fix accidentally-changed PageSize
SteveSandersonMS Aug 28, 2023
3d64f31
Clean up disposal
SteveSandersonMS Aug 28, 2023
db0c296
Remove all the pooling. Perf is the same.
SteveSandersonMS Aug 28, 2023
0d55544
Tidy and update tests
SteveSandersonMS Aug 28, 2023
2b22977
Add BufferedTextWriterTest
SteveSandersonMS Aug 28, 2023
52262d5
Tidy
SteveSandersonMS Aug 28, 2023
65e537d
Remove temporary comments
SteveSandersonMS Aug 29, 2023
2346a57
Revert sample changes
SteveSandersonMS Aug 29, 2023
4ff9b3f
Another revert
SteveSandersonMS Aug 29, 2023
f248a6a
Add E2E test
SteveSandersonMS Aug 29, 2023
c5c956b
Fix char array segments
SteveSandersonMS Aug 29, 2023
9e4ee1a
More performant fix
SteveSandersonMS Aug 29, 2023
e4ca2e7
Fix build
SteveSandersonMS Aug 29, 2023
d457dcb
Make a test more meaningful
SteveSandersonMS Aug 29, 2023
ba685c4
E2E test fix for Linux
SteveSandersonMS Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix char array segments
SteveSandersonMS committed Aug 29, 2023
commit c5c956b1644379dbaeccd1b71674ffce5100f9d7
12 changes: 6 additions & 6 deletions src/Components/Endpoints/src/Rendering/Buffering/TextChunk.cs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ internal readonly struct TextChunk
// by _type. That will reduce memory usage and improve locality.
private readonly string? _stringValue;
private readonly char _charValue;
private readonly ArraySegment<char> _charArraySegmentValue;
private readonly char[]? _charArray;
private readonly int _intValue;

public TextChunk(string value)
@@ -33,8 +33,8 @@ public TextChunk(char value)

public TextChunk(ArraySegment<char> value)
{
_type = TextChunkType.CharArraySegment;
_charArraySegmentValue = value;
_type = TextChunkType.CharArray;
_charArray = value.ToArray();
}

public TextChunk(int value)
@@ -51,8 +51,8 @@ public Task WriteToAsync(TextWriter writer, ref StringBuilder? tempBuffer)
return writer.WriteAsync(_stringValue);
case TextChunkType.Char:
return writer.WriteAsync(_charValue);
case TextChunkType.CharArraySegment:
return writer.WriteAsync(_charArraySegmentValue);
case TextChunkType.CharArray:
return writer.WriteAsync(_charArray);
case TextChunkType.Int:
// The same technique could be used to optimize writing other
// nonstring types, but currently only int is often used
@@ -65,5 +65,5 @@ public Task WriteToAsync(TextWriter writer, ref StringBuilder? tempBuffer)
}
}

private enum TextChunkType { Int, String, Char, CharArraySegment };
private enum TextChunkType { Int, String, Char, CharArray };
}
4 changes: 4 additions & 0 deletions src/Components/Endpoints/test/Buffering/TextChunkTest.cs
Original file line number Diff line number Diff line change
@@ -32,6 +32,10 @@ public async Task CanHoldCharArraySegment()
var chars = new char[] { 'a', 'b', 'c', 'd', 'e' };
var chunk = new TextChunk(new ArraySegment<char>(chars, 1, 3));
await chunk.WriteToAsync(_writer, ref _tempBuffer);

// See it still works when the underlying array is mutated
chars[2] = 'X';

Assert.Equal("bcd", _writer.ToString());
}