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

Commit 5d2536e

Browse files
committed
Fix async causing performance issues
1 parent 3a41b1d commit 5d2536e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Titanium.Web.Proxy/Helpers/CustomBinaryReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal async Task<string> ReadLineAsync()
3939
var lastChar = default(char);
4040
var buffer = new byte[1];
4141

42-
while (this.stream.Read(buffer, 0, 1) > 0)
42+
while ((await this.stream.ReadAsync(buffer, 0, 1)) > 0)
4343
{
4444
if (lastChar == '\r' && buffer[0] == '\n')
4545
{

Titanium.Web.Proxy/RequestHandler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ private static async Task HandleHttpSessionRequest(TcpClient client, string http
233233
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, null);
234234
break;
235235
}
236+
236237
#endif
237238
args.WebSession.Request.RequestUri = httpRemoteUri;
238239

@@ -269,7 +270,7 @@ await TcpHelper.SendRaw(clientStream, httpCmd, args.WebSession.Request.RequestHe
269270
}
270271

271272
//construct the web request that we are going to issue on behalf of the client.
272-
connection = await TcpConnectionManager.GetClient(args.WebSession.Request.RequestUri.Host, args.WebSession.Request.RequestUri.Port, args.IsHttps, version).ConfigureAwait(false);
273+
connection = await TcpConnectionManager.GetClient(args.WebSession.Request.RequestUri.Host, args.WebSession.Request.RequestUri.Port, args.IsHttps, version).ConfigureAwait(false);
273274

274275

275276
args.WebSession.Request.RequestLocked = true;
@@ -343,6 +344,8 @@ await WriteResponseStatus(args.WebSession.Response.HttpVersion, "417",
343344
return;
344345
}
345346

347+
await TcpConnectionManager.ReleaseClient(connection);
348+
346349
// read the next request
347350
httpCmd = await clientStreamReader.ReadLineAsync().ConfigureAwait(false);
348351

@@ -355,8 +358,6 @@ await WriteResponseStatus(args.WebSession.Response.HttpVersion, "417",
355358

356359
}
357360

358-
if (connection!=null)
359-
await TcpConnectionManager.ReleaseClient(connection);
360361
}
361362

362363
private static async Task WriteConnectResponse(StreamWriter clientStreamWriter, Version httpVersion)

0 commit comments

Comments
 (0)