Skip to content
This repository was archived by the owner on Nov 1, 2018. It is now read-only.

Commit d463b5e

Browse files
authored
Fix ReaderThrowsResetExceptionOnInvalidBody (#1420)
1 parent d28468c commit d463b5e

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

test/Common.Tests/Utilities/TestConnections.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,15 @@ public void Dispose()
6262

6363
public async Task Send(params string[] lines)
6464
{
65-
var text = string.Join("\r\n", lines);
66-
var writer = new StreamWriter(_stream, Encoding.GetEncoding("iso-8859-1"));
67-
for (var index = 0; index < text.Length; index++)
65+
var bytes = Encoding.ASCII.GetBytes(string.Join("\r\n", lines));
66+
67+
for (var index = 0; index < bytes.Length; index++)
6868
{
69-
var ch = text[index];
70-
writer.Write(ch);
71-
await writer.FlushAsync().ConfigureAwait(false);
69+
await _stream.WriteAsync(bytes, index, 1).ConfigureAwait(false);
70+
await _stream.FlushAsync().ConfigureAwait(false);
7271
// Re-add delay to help find socket input consumption bugs more consistently
7372
//await Task.Delay(TimeSpan.FromMilliseconds(5));
7473
}
75-
await writer.FlushAsync().ConfigureAwait(false);
76-
await _stream.FlushAsync().ConfigureAwait(false);
7774
}
7875

7976
public async Task<int> ReadCharAsync()

test/IIS.Tests/ClientDisconnectTests.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,15 @@ public async Task ReaderThrowsCancelledException()
206206
[ConditionalFact]
207207
public async Task ReaderThrowsResetExceptionOnInvalidBody()
208208
{
209+
var requestStartedCompletionSource = CreateTaskCompletionSource();
209210
var requestCompletedCompletionSource = CreateTaskCompletionSource();
210211

211212
Exception exception = null;
212213

213214
var data = new byte[1024];
214215
using (var testServer = await TestServer.Create(async ctx =>
215216
{
217+
requestStartedCompletionSource.SetResult(true);
216218
try
217219
{
218220
await ctx.Request.Body.ReadAsync(data);
@@ -233,10 +235,19 @@ await connection.Send(
233235
"Host: localhost",
234236
"Connection: close",
235237
"",
236-
"ZZZ",
237238
"");
238-
await requestCompletedCompletionSource.Task.DefaultTimeout();
239+
240+
await requestStartedCompletionSource.Task;
241+
await connection.Send(
242+
"ZZZZZZZZZZZZZ");
243+
244+
await connection.Receive(
245+
"HTTP/1.1 400 Bad Request",
246+
""
247+
);
248+
239249
}
250+
await requestCompletedCompletionSource.Task.DefaultTimeout();
240251
}
241252

242253
Assert.IsType<ConnectionResetException>(exception);

0 commit comments

Comments
 (0)