This is an automated email from the ASF dual-hosted git repository.
jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
The following commit(s) were added to refs/heads/master by this push:
new d4e1eb9 THRIFT-5398 ThreadPoolServer not stoppable via
CancellationToken Client: netstd Patch: Jens Geyer
d4e1eb9 is described below
commit d4e1eb98525faffafdba4f36f44e3e7382cc0fd0
Author: Jens Geyer <[email protected]>
AuthorDate: Thu Apr 15 16:48:21 2021 +0200
THRIFT-5398 ThreadPoolServer not stoppable via CancellationToken
Client: netstd
Patch: Jens Geyer
This closes #2376
---
lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs | 8 +++++---
.../Thrift/Transport/Server/TNamedPipeServerTransport.cs | 5 +++++
lib/netstd/Thrift/Transport/Server/TServerTransport.cs | 14 ++------------
3 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs
b/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs
index 20e659d..877d595 100644
--- a/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs
+++ b/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs
@@ -172,19 +172,21 @@ namespace Thrift.Server
if (ServerEventHandler != null)
await ServerEventHandler.PreServeAsync(cancellationToken);
- while (!stop)
+ while (!(stop ||
ServerCancellationToken.IsCancellationRequested))
{
- int failureCount = 0;
try
{
TTransport client = await
ServerTransport.AcceptAsync(cancellationToken);
ThreadPool.QueueUserWorkItem(this.Execute, client);
}
+ catch (TaskCanceledException)
+ {
+ stop = true;
+ }
catch (TTransportException ttx)
{
if (!stop || ttx.Type !=
TTransportException.ExceptionType.Interrupted)
{
- ++failureCount;
LogError(ttx.ToString());
}
diff --git a/lib/netstd/Thrift/Transport/Server/TNamedPipeServerTransport.cs
b/lib/netstd/Thrift/Transport/Server/TNamedPipeServerTransport.cs
index 307b7f8..35a037d 100644
--- a/lib/netstd/Thrift/Transport/Server/TNamedPipeServerTransport.cs
+++ b/lib/netstd/Thrift/Transport/Server/TNamedPipeServerTransport.cs
@@ -264,6 +264,11 @@ namespace Thrift.Transport.Server
Close();
throw;
}
+ catch (TaskCanceledException)
+ {
+ Close();
+ throw; // let it bubble up
+ }
catch (Exception e)
{
Close();
diff --git a/lib/netstd/Thrift/Transport/Server/TServerTransport.cs
b/lib/netstd/Thrift/Transport/Server/TServerTransport.cs
index eee50fb..5366114 100644
--- a/lib/netstd/Thrift/Transport/Server/TServerTransport.cs
+++ b/lib/netstd/Thrift/Transport/Server/TServerTransport.cs
@@ -36,19 +36,9 @@ namespace Thrift.Transport
public abstract void Close();
public abstract bool IsClientPending();
- protected virtual async ValueTask<TTransport>
AcceptImplementationAsync()
- {
- return await AcceptImplementationAsync(CancellationToken.None);
- }
-
- protected abstract ValueTask<TTransport>
AcceptImplementationAsync(CancellationToken cancellationToken);
-
- public async ValueTask<TTransport> AcceptAsync()
- {
- return await AcceptAsync(CancellationToken.None);
- }
+ protected abstract ValueTask<TTransport>
AcceptImplementationAsync(CancellationToken cancellationToken = default);
- public async ValueTask<TTransport> AcceptAsync(CancellationToken
cancellationToken)
+ public async ValueTask<TTransport> AcceptAsync(CancellationToken
cancellationToken = default)
{
var transport = await AcceptImplementationAsync(cancellationToken);