diff --git a/SimpleRabbit.NetCore/Service/BasicRabbitService.cs b/SimpleRabbit.NetCore/Service/BasicRabbitService.cs index 5a593d2..8e90b7d 100644 --- a/SimpleRabbit.NetCore/Service/BasicRabbitService.cs +++ b/SimpleRabbit.NetCore/Service/BasicRabbitService.cs @@ -15,6 +15,7 @@ public interface IBasicRabbitService : IDisposable public abstract class BasicRabbitService : IBasicRabbitService { + private readonly object _lock = new object(); private const ushort DefaultRequestedHeartBeat = 5; private const int DefaultNetworkRecoveryInterval = 10; @@ -79,7 +80,7 @@ protected BasicRabbitService(RabbitConfiguration config) public IBasicProperties GetBasicProperties() { - lock(this) + lock (_lock) { return Channel.CreateBasicProperties(); } @@ -87,7 +88,7 @@ public IBasicProperties GetBasicProperties() public void ClearConnection() { - lock (this) + lock (_lock) { if (_disposed) { @@ -95,11 +96,13 @@ public void ClearConnection() } try { + _channel?.Close(); _channel?.Dispose(); _channel = null; } finally { + _connection?.Close(); _connection?.Dispose(); _connection = null; } @@ -109,7 +112,7 @@ public void ClearConnection() public void Close() { - lock (this) + lock (_lock) { if (_disposed) {