Skip to content

Commit 4b94d48

Browse files
xwipeoutxmauroservienti
authored andcommitted
Moved the latch signal up the stack, to ensure it signals when the connection setup fails.
1 parent cb714e0 commit 4b94d48

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/NServiceBus.Transport.Sql.Shared/Receiving/ProcessWithNativeTransaction.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public override async Task ProcessMessage(CancellationTokenSource stopBatchCance
2626
{
2727
Message message = null;
2828
var context = new ContextBag();
29+
var hasLatchBeenSignalled = false;
2930

3031
try
3132
{
@@ -41,6 +42,7 @@ public override async Task ProcessMessage(CancellationTokenSource stopBatchCance
4142
finally
4243
{
4344
receiveLatch.Signal();
45+
hasLatchBeenSignalled = true;
4446
}
4547

4648
if (receiveResult == MessageReadResult.NoMessage)
@@ -87,6 +89,13 @@ public override async Task ProcessMessage(CancellationTokenSource stopBatchCance
8789
}
8890
failureInfoStorage.RecordFailureInfoForMessage(message.TransportId, ex, context);
8991
}
92+
finally
93+
{
94+
if (!hasLatchBeenSignalled)
95+
{
96+
receiveLatch.Signal();
97+
}
98+
}
9099
}
91100

92101
async Task<bool> TryProcess(Message message, TransportTransaction transportTransaction, ContextBag context, CancellationToken cancellationToken)

src/NServiceBus.Transport.Sql.Shared/Receiving/ProcessWithNoTransaction.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public override async Task ProcessMessage(CancellationTokenSource stopBatchCance
2121
{
2222
Message message = null;
2323
var context = new ContextBag();
24+
var hasLatchBeenSignalled = false;
2425

2526
using (var connection = await connectionFactory.OpenNewConnection(cancellationToken).ConfigureAwait(false))
2627
{
@@ -37,6 +38,7 @@ public override async Task ProcessMessage(CancellationTokenSource stopBatchCance
3738
finally
3839
{
3940
receiveLatch.Signal();
41+
hasLatchBeenSignalled = true;
4042
}
4143

4244
if (receiveResult == MessageReadResult.NoMessage)
@@ -87,6 +89,13 @@ await ErrorQueue
8789
// Since this is TransactionMode.None, we don't care whether error handling says handled or retry. Message is gone either way.
8890
_ = await HandleError(ex, message, transportTransaction, 1, context, cancellationToken).ConfigureAwait(false);
8991
}
92+
finally
93+
{
94+
if (!hasLatchBeenSignalled)
95+
{
96+
receiveLatch.Signal();
97+
}
98+
}
9099
}
91100
}
92101

src/NServiceBus.Transport.Sql.Shared/Receiving/ProcessWithTransactionScope.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public override async Task ProcessMessage(CancellationTokenSource stopBatchCance
2222
{
2323
Message message = null;
2424
var context = new ContextBag();
25+
var hasLatchBeenSignalled = false;
2526

2627
try
2728
{
@@ -36,6 +37,7 @@ public override async Task ProcessMessage(CancellationTokenSource stopBatchCance
3637
finally
3738
{
3839
receiveLatch.Signal();
40+
hasLatchBeenSignalled = true;
3941
}
4042

4143
if (receiveResult == MessageReadResult.NoMessage)
@@ -79,6 +81,13 @@ public override async Task ProcessMessage(CancellationTokenSource stopBatchCance
7981
}
8082
failureInfoStorage.RecordFailureInfoForMessage(message.TransportId, ex, context);
8183
}
84+
finally
85+
{
86+
if (!hasLatchBeenSignalled)
87+
{
88+
receiveLatch.Signal();
89+
}
90+
}
8291
}
8392

8493
async Task<bool> TryProcess(Message message, TransportTransaction transportTransaction, ContextBag context, CancellationToken cancellationToken)

0 commit comments

Comments
 (0)