Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 42ac058

Browse files
committed
nullpointer fix in race conditions
1 parent 2afbd3c commit 42ac058

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ private async Task readRequestBodyAsync(CancellationToken cancellationToken)
9494
if (request.HttpVersion == HttpHeader.Version20)
9595
{
9696
request.Http2BodyData = new MemoryStream();
97-
request.ReadHttp2BodyTaskCompletionSource = new TaskCompletionSource<bool>();
97+
98+
var tcs = new TaskCompletionSource<bool>();
99+
request.ReadHttp2BodyTaskCompletionSource = tcs;
98100

99101
// signal to HTTP/2 copy frame method to continue
100102
ReadHttp2BodyTaskCompletionSource.SetResult(true);
101103

102-
await request.ReadHttp2BodyTaskCompletionSource.Task;
104+
await tcs.Task;
103105
}
104106
else
105107
{
@@ -158,12 +160,14 @@ private async Task readResponseBodyAsync(CancellationToken cancellationToken)
158160
if (response.HttpVersion == HttpHeader.Version20)
159161
{
160162
response.Http2BodyData = new MemoryStream();
161-
response.ReadHttp2BodyTaskCompletionSource = new TaskCompletionSource<bool>();
163+
164+
var tcs = new TaskCompletionSource<bool>();
165+
response.ReadHttp2BodyTaskCompletionSource = tcs;
162166

163167
// signal to HTTP/2 copy frame method to continue
164168
ReadHttp2BodyTaskCompletionSource.SetResult(true);
165169

166-
await response.ReadHttp2BodyTaskCompletionSource.Task;
170+
await tcs.Task;
167171
}
168172
else
169173
{

0 commit comments

Comments
 (0)