Skip to content

Commit 12b2624

Browse files
authored
Fix BasicRabbitService disconnection (#80)
1 parent 5669e4d commit 12b2624

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

SimpleRabbit.NetCore/Service/BasicRabbitService.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public interface IBasicRabbitService : IDisposable
1515

1616
public abstract class BasicRabbitService : IBasicRabbitService
1717
{
18+
private readonly object _lock = new object();
1819
private const ushort DefaultRequestedHeartBeat = 5;
1920
private const int DefaultNetworkRecoveryInterval = 10;
2021

@@ -79,27 +80,29 @@ protected BasicRabbitService(RabbitConfiguration config)
7980

8081
public IBasicProperties GetBasicProperties()
8182
{
82-
lock(this)
83+
lock (_lock)
8384
{
8485
return Channel.CreateBasicProperties();
8586
}
8687
}
8788

8889
public void ClearConnection()
8990
{
90-
lock (this)
91+
lock (_lock)
9192
{
9293
if (_disposed)
9394
{
9495
return;
9596
}
9697
try
9798
{
99+
_channel?.Close();
98100
_channel?.Dispose();
99101
_channel = null;
100102
}
101103
finally
102104
{
105+
_connection?.Close();
103106
_connection?.Dispose();
104107
_connection = null;
105108
}
@@ -109,7 +112,7 @@ public void ClearConnection()
109112

110113
public void Close()
111114
{
112-
lock (this)
115+
lock (_lock)
113116
{
114117
if (_disposed)
115118
{

0 commit comments

Comments
 (0)