Skip to content

Commit

Permalink
Fix #1140 by assigning the new Model to _innerChannel at the correct …
Browse files Browse the repository at this point in the history
…place.
  • Loading branch information
lukebakken committed Feb 21, 2022
1 parent 389819a commit 3d00716
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,13 @@ private bool TryPerformAutomaticRecovery()
// 2. Recover queues
// 3. Recover bindings
// 4. Recover consumers
using var recoveryChannel = _innerConnection.CreateModel();
RecoverExchanges(recoveryChannel);
RecoverQueues(recoveryChannel);
RecoverBindings(recoveryChannel);
using (var recoveryChannel = _innerConnection.CreateModel())
{
RecoverExchanges(recoveryChannel);
RecoverQueues(recoveryChannel);
RecoverBindings(recoveryChannel);
}

}
RecoverModelsAndItsConsumers();
}
Expand Down
9 changes: 8 additions & 1 deletion projects/RabbitMQ.Client/client/impl/AutorecoveringModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,19 @@ internal void AutomaticallyRecover(AutorecoveringConnection conn, bool recoverCo
newChannel.TxSelect();
}

/*
* https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/1140
* If this assignment is not done before recovering consumers, there is a good
* chance that an invalid Model will be used to handle a basic.deliver frame,
* with the resulting basic.ack never getting sent out.
*/
_innerChannel = newChannel;

if (recoverConsumers)
{
_connection.RecoverConsumers(this, newChannel);
}

_innerChannel = newChannel;
_innerChannel.RunRecoveryEventHandlers(this);
}

Expand Down
4 changes: 2 additions & 2 deletions projects/Unit/TestConnectionRecovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void TestBasicAckAfterChannelRecovery()
Wait(allMessagesSeenLatch);
}

[Fact(Skip="TODO flaky")]
[Fact]
public void TestBasicNackAfterChannelRecovery()
{
var allMessagesSeenLatch = new ManualResetEventSlim(false);
Expand All @@ -134,7 +134,7 @@ public void TestBasicNackAfterChannelRecovery()
Wait(allMessagesSeenLatch);
}

[Fact(Skip="TODO flaky")]
[Fact]
public void TestBasicRejectAfterChannelRecovery()
{
var allMessagesSeenLatch = new ManualResetEventSlim(false);
Expand Down

0 comments on commit 3d00716

Please sign in to comment.