File tree Expand file tree Collapse file tree 3 files changed +26
-4
lines changed
RabbitMQ.Client/client/impl Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -216,7 +216,7 @@ public void Dispose()
216
216
217
217
try
218
218
{
219
- this . Abort ( ) ;
219
+ this . Abort ( TimeSpan . FromSeconds ( 15 ) ) ;
220
220
}
221
221
catch ( Exception )
222
222
{
Original file line number Diff line number Diff line change 42
42
43
43
namespace RabbitMQ . Client . Framing . Impl
44
44
{
45
- #nullable enable
45
+ #nullable enable
46
46
internal sealed partial class Connection : IConnection
47
47
{
48
48
private bool _disposed ;
@@ -410,7 +410,7 @@ public void Dispose()
410
410
411
411
try
412
412
{
413
- this . Abort ( ) ;
413
+ this . Abort ( TimeSpan . FromSeconds ( 15 ) ) ;
414
414
_mainLoopTask . Wait ( ) ;
415
415
}
416
416
catch ( OperationInterruptedException )
Original file line number Diff line number Diff line change 31
31
32
32
using System ;
33
33
using System . Threading ;
34
-
34
+ using System . Threading . Tasks ;
35
35
using RabbitMQ . Client . Events ;
36
36
37
37
using Xunit ;
@@ -42,6 +42,7 @@ namespace RabbitMQ.Client.Unit
42
42
[ Collection ( "NoParallelization" ) ]
43
43
public class TestConnectionBlocked : IntegrationFixture
44
44
{
45
+ private readonly ManualResetEventSlim _connDisposed = new ManualResetEventSlim ( false ) ;
45
46
private readonly object _lockObject = new object ( ) ;
46
47
private bool _notified ;
47
48
@@ -68,6 +69,7 @@ protected override void ReleaseResources()
68
69
[ Fact ]
69
70
public void TestConnectionBlockedNotification ( )
70
71
{
72
+ _notified = false ;
71
73
_conn . ConnectionBlocked += HandleBlocked ;
72
74
_conn . ConnectionUnblocked += HandleUnblocked ;
73
75
@@ -85,5 +87,25 @@ public void TestConnectionBlockedNotification()
85
87
Assert . True ( false , "Unblock notification not received." ) ;
86
88
}
87
89
}
90
+
91
+ [ Fact ]
92
+ public void TestDisposeOnBlockedConnectionDoesNotHang ( )
93
+ {
94
+ _notified = false ;
95
+ Block ( ) ;
96
+ Task . Factory . StartNew ( DisposeConnection ) ;
97
+
98
+ if ( ! _connDisposed . Wait ( TimeSpan . FromSeconds ( 20 ) ) )
99
+ {
100
+ Unblock ( ) ;
101
+ Assert . True ( false , "Dispose must have finished within 20 seconds after starting" ) ;
102
+ }
103
+ }
104
+
105
+ private void DisposeConnection ( )
106
+ {
107
+ _conn . Dispose ( ) ;
108
+ _connDisposed . Set ( ) ;
109
+ }
88
110
}
89
111
}
You can’t perform that action at this time.
0 commit comments