summaryrefslogtreecommitdiff
path: root/lib/netstd
diff options
context:
space:
mode:
authorphxnsharp <nsharp@phoenix-int.com>2021-05-21 23:36:30 +0200
committerJens Geyer <jensg@apache.org>2021-05-26 22:34:18 +0200
commit9a4802ab411f1f45b58a8eae015707502e36b8ed (patch)
treead66af51093c72b9cd1b82347c9143274d1f89dd /lib/netstd
parent63d114de97f8ddb67c1fb33d75ccb91a3b487b92 (diff)
downloadthrift-9a4802ab411f1f45b58a8eae015707502e36b8ed.tar.gz
THRIFT-5419 Incorrect usage of thread pool in TThreadPoolAsyncServer may lead to poor performance
Client: netstd Patch: Nathan P Sharp, Jens Geyer This closes #2395
Diffstat (limited to 'lib/netstd')
-rw-r--r--lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs b/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs
index 7a5254ae8..49593cc0d 100644
--- a/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs
+++ b/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs
@@ -178,7 +178,7 @@ namespace Thrift.Server
try
{
TTransport client = await ServerTransport.AcceptAsync(cancellationToken);
- ThreadPool.QueueUserWorkItem(this.Execute, client);
+ _ = Task.Run(async () => await ExecuteAsync(client), cancellationToken); // intentionally ignoring retval
}
catch (TaskCanceledException)
{
@@ -219,11 +219,11 @@ namespace Thrift.Server
/// threadContext will be a TTransport instance
/// </summary>
/// <param name="threadContext"></param>
- private void Execute(object threadContext)
+ private async Task ExecuteAsync(TTransport client)
{
var cancellationToken = ServerCancellationToken;
- using (TTransport client = (TTransport)threadContext)
+ using (client)
{
ITAsyncProcessor processor = ProcessorFactory.GetAsyncProcessor(client, this);
TTransport inputTransport = null;
@@ -242,12 +242,12 @@ namespace Thrift.Server
//Recover event handler (if any) and fire createContext server event when a client connects
if (ServerEventHandler != null)
- connectionContext = ServerEventHandler.CreateContextAsync(inputProtocol, outputProtocol, cancellationToken).Result;
+ connectionContext = await ServerEventHandler.CreateContextAsync(inputProtocol, outputProtocol, cancellationToken);
//Process client requests until client disconnects
while (!stop)
{
- if (! inputTransport.PeekAsync(cancellationToken).Result)
+ if (! await inputTransport.PeekAsync(cancellationToken))
break;
//Fire processContext server event
@@ -255,10 +255,10 @@ namespace Thrift.Server
//That is to say it may be many minutes between the event firing and the client request
//actually arriving or the client may hang up without ever makeing a request.
if (ServerEventHandler != null)
- ServerEventHandler.ProcessContextAsync(connectionContext, inputTransport, cancellationToken).Wait();
+ await ServerEventHandler.ProcessContextAsync(connectionContext, inputTransport, cancellationToken);
//Process client request (blocks until transport is readable)
- if (!processor.ProcessAsync(inputProtocol, outputProtocol, cancellationToken).Result)
+ if (! await processor.ProcessAsync(inputProtocol, outputProtocol, cancellationToken))
break;
}
}
@@ -274,7 +274,7 @@ namespace Thrift.Server
//Fire deleteContext server event after client disconnects
if (ServerEventHandler != null)
- ServerEventHandler.DeleteContextAsync(connectionContext, inputProtocol, outputProtocol, cancellationToken).Wait();
+ await ServerEventHandler.DeleteContextAsync(connectionContext, inputProtocol, outputProtocol, cancellationToken);
}
finally