Skip to content

Commit 8a39df9

Browse files
committed
Hardening MessageContext.FlushOutgoingMessags() against nulls. Closes GH-2006
1 parent 1a7ba62 commit 8a39df9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Wolverine/Runtime/MessageBus.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ public ValueTask BroadcastToTopicAsync(string topicName, object message, Deliver
252252

253253
internal async ValueTask PersistOrSendAsync(Envelope envelope)
254254
{
255+
if (envelope is null) return; // Not sure how this would happen
256+
255257
if (envelope.Sender is null)
256258
{
257259
throw new InvalidOperationException("Envelope has not been routed");
@@ -310,7 +312,7 @@ internal async ValueTask PersistOrSendAsync(params Envelope[] outgoing)
310312
// the sender is currently latched
311313
var envelopes = outgoing.Where(isDurable).ToArray();
312314
foreach (var envelope in envelopes.Where(x =>
313-
x.Sender is { Latched: true } && x.Status == EnvelopeStatus.Outgoing))
315+
x is { Sender: { Latched: true }, Status: EnvelopeStatus.Outgoing }))
314316
envelope.OwnerId = TransportConstants.AnyNode;
315317

316318
await Transaction.PersistAsync(envelopes);

src/Wolverine/Runtime/MessageContext.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ public async Task FlushOutgoingMessagesAsync()
109109
$"This MessageContext does not allow multiple calls to {nameof(FlushOutgoingMessagesAsync)} because {nameof(MultiFlushMode)} = {MultiFlushMode}");
110110
}
111111
}
112-
113112

114113
await AssertAnyRequiredResponseWasGenerated();
115114

@@ -120,6 +119,9 @@ public async Task FlushOutgoingMessagesAsync()
120119

121120
foreach (var envelope in Outstanding)
122121
{
122+
// https://github.com/JasperFx/wolverine/issues/2006
123+
if (envelope == null) continue;
124+
123125
try
124126
{
125127
if (envelope.IsScheduledForLater(DateTimeOffset.UtcNow))

0 commit comments

Comments
 (0)