Skip to content

Commit aff8436

Browse files
committed
Fix up use of Enqueue for continuations
No sense in doing the continuation if the channel is not open.
1 parent be1d1e3 commit aff8436

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

projects/RabbitMQ.Client/Impl/ChannelBase.cs

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,15 @@ await _rpcSemaphore.WaitAsync(k.CancellationToken)
381381
try
382382
{
383383
enqueued = Enqueue(k);
384+
if (enqueued)
385+
{
386+
var method = new ChannelOpen();
387+
await ModelSendAsync(in method, k.CancellationToken)
388+
.ConfigureAwait(false);
384389

385-
var method = new ChannelOpen();
386-
await ModelSendAsync(in method, k.CancellationToken)
387-
.ConfigureAwait(false);
388-
389-
bool result = await k;
390-
Debug.Assert(result);
390+
bool result = await k;
391+
Debug.Assert(result);
392+
}
391393
return this;
392394
}
393395
finally
@@ -877,12 +879,13 @@ await ModelSendAsync(in method, k.CancellationToken)
877879
else
878880
{
879881
enqueued = Enqueue(k);
880-
881-
await ModelSendAsync(in method, k.CancellationToken)
882-
.ConfigureAwait(false);
883-
884-
bool result = await k;
885-
Debug.Assert(result);
882+
if (enqueued)
883+
{
884+
await ModelSendAsync(in method, k.CancellationToken)
885+
.ConfigureAwait(false);
886+
bool result = await k;
887+
Debug.Assert(result);
888+
}
886889
}
887890

888891
return;
@@ -912,12 +915,17 @@ await _rpcSemaphore.WaitAsync(k.CancellationToken)
912915
try
913916
{
914917
enqueued = Enqueue(k);
915-
916-
var method = new BasicConsume(queue, consumerTag, noLocal, autoAck, exclusive, false, arguments);
917-
await ModelSendAsync(in method, k.CancellationToken)
918-
.ConfigureAwait(false);
919-
920-
return await k;
918+
if (enqueued)
919+
{
920+
var method = new BasicConsume(queue, consumerTag, noLocal, autoAck, exclusive, false, arguments);
921+
await ModelSendAsync(in method, k.CancellationToken)
922+
.ConfigureAwait(false);
923+
return await k;
924+
}
925+
else
926+
{
927+
return string.Empty;
928+
}
921929
}
922930
finally
923931
{
@@ -1632,14 +1640,16 @@ await _rpcSemaphore.WaitAsync(k.CancellationToken)
16321640
.ConfigureAwait(false);
16331641
try
16341642
{
1635-
Enqueue(k);
1636-
1637-
var method = new QueueUnbind(queue, exchange, routingKey, arguments);
1638-
await ModelSendAsync(in method, k.CancellationToken)
1639-
.ConfigureAwait(false);
1643+
enqueued = Enqueue(k);
1644+
if (enqueued)
1645+
{
1646+
var method = new QueueUnbind(queue, exchange, routingKey, arguments);
1647+
await ModelSendAsync(in method, k.CancellationToken)
1648+
.ConfigureAwait(false);
16401649

1641-
bool result = await k;
1642-
Debug.Assert(result);
1650+
bool result = await k;
1651+
Debug.Assert(result);
1652+
}
16431653
return;
16441654
}
16451655
finally
@@ -1719,14 +1729,16 @@ await _rpcSemaphore.WaitAsync(k.CancellationToken)
17191729
.ConfigureAwait(false);
17201730
try
17211731
{
1722-
Enqueue(k);
1723-
1724-
var method = new TxSelect();
1725-
await ModelSendAsync(in method, k.CancellationToken)
1726-
.ConfigureAwait(false);
1732+
enqueued = Enqueue(k);
1733+
if (enqueued)
1734+
{
1735+
var method = new TxSelect();
1736+
await ModelSendAsync(in method, k.CancellationToken)
1737+
.ConfigureAwait(false);
17271738

1728-
bool result = await k;
1729-
Debug.Assert(result);
1739+
bool result = await k;
1740+
Debug.Assert(result);
1741+
}
17301742
return;
17311743
}
17321744
finally

0 commit comments

Comments
 (0)