Closed knallle closed 1 month ago
thanks for the report @knallle I'm not familiar with CancellationTokenSource
being used as singleton but if you pass the stoppingToken
it works as expected:
await foreach (var msg in connection.SubscribeAsync<int>(subject).WithCancellation(stoppingToken))
edit: even if I don't pass any token to SubscribeAsync I see the same behaviour described above.
@mtmk Thanks for having a look! The problem was, as you pointed out, my handling of the CancellationTokenSource. I was misled by a Medium post.
Thanks for your hard work! 👍
Observed behavior
When cancelling my Console Application (minimal example provided below), it takes exactly 30 seconds for the program to terminate after calling for cancellation with CTRL-C.
Debugging with Parallel Stacks in Visual Studio led me to
NATS.Client.Core.NatsConnection.SubScribeAsync()
:It is clearly stated that the channel reader is not cancelled and the incoming CancellationToken is not passed to
sub.Msgs.ReadAllAsync()
.Expected behavior
I expect the program to terminate sooner than 30 seconds after cancellation is called.
If immediate cancellation is impossible, enabling the developer to set the timeout to something less than 30 seconds would be great.
Server and client version
nats-server: v2.10.20 NATS.Net: 2.4.0
Host environment
Steps to reproduce
Minimal working example
Program.cs
MyService.cs