Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update IConsumerRegister.Default.cs to make dispose thread safe #1438

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/DotNetCore.CAP/Internal/IConsumerRegister.Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class ConsumerRegister : IConsumerRegister
private IConsumerClientFactory _consumerClientFactory = default!;
private CancellationTokenSource _cts = new();
private IDispatcher _dispatcher = default!;
private bool _disposed;
private int _disposed;
private bool _isHealthy = true;

private MethodMatcherCache _selector = default!;
Expand Down Expand Up @@ -67,7 +67,7 @@ public Task Start(CancellationToken stoppingToken)

Execute();

_disposed = false;
_disposed = 0;

return Task.CompletedTask;
}
Expand All @@ -87,9 +87,8 @@ public void ReStart(bool force = false)

public void Dispose()
{
if (_disposed) return;

_disposed = true;
if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 1)
return;

try
{
Expand Down Expand Up @@ -394,4 +393,4 @@ private void TracingError(long? tracingTimestamp, TransportMessage message, Brok
}

#endregion
}
}