Skip to content

Commit 8bc16b8

Browse files
authored
Merge pull request #1454 from rabbitmq/rabbitmq-dotnet-client-1043-6.x
Back-port https://github.com/rabbitmq/rabbitmq-dotnet-client/pull/145…
2 parents b3840a9 + 620e798 commit 8bc16b8

File tree

2 files changed

+79
-5
lines changed

2 files changed

+79
-5
lines changed

projects/RabbitMQ.Client/client/impl/ModelBase.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,11 +1194,28 @@ public void BasicPublish(string exchange,
11941194
}
11951195
}
11961196

1197-
_Private_BasicPublish(exchange,
1198-
routingKey,
1199-
mandatory,
1200-
basicProperties,
1201-
body);
1197+
try
1198+
{
1199+
_Private_BasicPublish(exchange,
1200+
routingKey,
1201+
mandatory,
1202+
basicProperties,
1203+
body);
1204+
}
1205+
catch
1206+
{
1207+
if (NextPublishSeqNo > 0)
1208+
{
1209+
lock (_confirmLock)
1210+
{
1211+
NextPublishSeqNo--;
1212+
_pendingDeliveryTags.RemoveLast();
1213+
_deliveryTagsCountdown.Reset(_pendingDeliveryTags.Count);
1214+
}
1215+
}
1216+
1217+
throw;
1218+
}
12021219
}
12031220

12041221
public void UpdateSecret(string newSecret, string reason)

projects/Unit/TestConfirmSelect.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
3030
//---------------------------------------------------------------------------
3131

32+
using System;
3233
using NUnit.Framework;
3334

3435
namespace RabbitMQ.Client.Unit
@@ -63,5 +64,61 @@ protected void Publish()
6364
{
6465
Model.BasicPublish("", "amq.fanout", null, encoding.GetBytes("message"));
6566
}
67+
68+
[Test]
69+
[TestCase(255)]
70+
[TestCase(256)]
71+
public void TestDeliveryTagDiverged_GH1043(int correlationIdLength)
72+
{
73+
bool.TryParse(Environment.GetEnvironmentVariable("RABBITMQ_VERBOSE"), out bool verbose);
74+
75+
byte[] body = RandomMessageBody();
76+
77+
Model.ExchangeDeclare("sample", "fanout", autoDelete: true);
78+
if (verbose)
79+
{
80+
Model.BasicAcks += (s, e) => Console.WriteLine("Acked {0}", e.DeliveryTag);
81+
}
82+
Model.ConfirmSelect();
83+
84+
IBasicProperties properties = Model.CreateBasicProperties();
85+
if (verbose)
86+
{
87+
Console.WriteLine("Client delivery tag {0}", Model.NextPublishSeqNo);
88+
}
89+
Model.BasicPublish(exchange: "sample", routingKey: string.Empty, properties, body);
90+
Model.WaitForConfirmsOrDie();
91+
92+
try
93+
{
94+
properties = Model.CreateBasicProperties();
95+
properties.CorrelationId = new string('o', correlationIdLength);
96+
if (verbose)
97+
{
98+
Console.WriteLine("Client delivery tag {0}", Model.NextPublishSeqNo);
99+
}
100+
Model.BasicPublish("sample", string.Empty, properties, body);
101+
Model.WaitForConfirmsOrDie();
102+
}
103+
catch (Exception e)
104+
{
105+
if (verbose)
106+
{
107+
Console.WriteLine("Error when trying to publish with long string: {0}", e.Message);
108+
}
109+
}
110+
111+
properties = Model.CreateBasicProperties();
112+
if (verbose)
113+
{
114+
Console.WriteLine("Client delivery tag {0}", Model.NextPublishSeqNo);
115+
}
116+
Model.BasicPublish("sample", string.Empty, properties, body);
117+
Model.WaitForConfirmsOrDie();
118+
if (verbose)
119+
{
120+
Console.WriteLine("I'm done...");
121+
}
122+
}
66123
}
67124
}

0 commit comments

Comments
 (0)