Skip to content

Commit 011ed4e

Browse files
committed
Alternative to previous commit, stop receviers and shutdown with already cancelled token. This should terminate ASAP BUT still cleanup all resources if properly implemented by transports/persisters.
1 parent 13fa363 commit 011ed4e

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/ServiceControl.Audit/Auditing/AuditIngestion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ async Task EnsureStopped(CancellationToken cancellationToken)
185185
try
186186
{
187187
await startStopSemaphore.WaitAsync(cancellationToken);
188-
await StopAndTeardownInfrastructure(cancellationToken);
188+
await StopAndTeardownInfrastructure(new CancellationToken(canceled: true));
189189
}
190190
finally
191191
{

src/ServiceControl/Operations/ErrorIngestion.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ public override async Task StopAsync(CancellationToken cancellationToken)
132132
{
133133
try
134134
{
135-
await stoppingToken.CancelAsync();
136135
await watchdog.Stop(cancellationToken);
137136
channel.Writer.Complete();
138137
await base.StopAsync(cancellationToken);
@@ -262,11 +261,8 @@ async Task StopAndTeardownInfrastructure(CancellationToken cancellationToken)
262261
}
263262
}
264263

265-
async Task OnMessage(MessageContext messageContext, CancellationToken cancellationTokenParent)
264+
async Task OnMessage(MessageContext messageContext, CancellationToken cancellationToken)
266265
{
267-
using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationTokenParent, stoppingToken.Token);
268-
var cancellationToken = cts.Token;
269-
270266
if (settings.MessageFilter != null && settings.MessageFilter(messageContext))
271267
{
272268
return;
@@ -297,7 +293,7 @@ async Task EnsureStopped(CancellationToken cancellationToken = default)
297293
try
298294
{
299295
await startStopSemaphore.WaitAsync(cancellationToken);
300-
await StopAndTeardownInfrastructure(cancellationToken);
296+
await StopAndTeardownInfrastructure(new CancellationToken(canceled: true));
301297
}
302298
finally
303299
{
@@ -311,7 +307,6 @@ async Task EnsureStopped(CancellationToken cancellationToken = default)
311307
TransportInfrastructure transportInfrastructure;
312308
IMessageReceiver messageReceiver;
313309

314-
readonly CancellationTokenSource stoppingToken = new();
315310
readonly Settings settings;
316311
readonly ITransportCustomization transportCustomization;
317312
readonly TransportSettings transportSettings;

0 commit comments

Comments
 (0)