From f97bc005d5311a0f742940db489e95c5352477ae Mon Sep 17 00:00:00 2001 From: Dave Cluderay Date: Thu, 28 Apr 2022 18:57:37 +0100 Subject: [PATCH] #46 Handle scenarios where the correlation ID is present, but null, in headers --- src/NServiceBus.Router/Pipeline/Forwarding/ReplyTraceRule.cs | 4 ++-- .../Pipeline/Prerouting/ReplyPreroutingTerminator.cs | 3 ++- src/NServiceBus.Router/TypeLengthValueDecoder.cs | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/NServiceBus.Router/Pipeline/Forwarding/ReplyTraceRule.cs b/src/NServiceBus.Router/Pipeline/Forwarding/ReplyTraceRule.cs index 6274773..e3c263c 100644 --- a/src/NServiceBus.Router/Pipeline/Forwarding/ReplyTraceRule.cs +++ b/src/NServiceBus.Router/Pipeline/Forwarding/ReplyTraceRule.cs @@ -75,7 +75,7 @@ protected void AddTraceHeadersForRoutingBackReply(BaseForwardRuleContext context newCorrelationId = newCorrelationId.AppendTLV("reply-to", replyToHeader); } - if (context.ForwardedHeaders.TryGetValue(Headers.CorrelationId, out var correlationId)) + if (context.ForwardedHeaders.TryGetValue(Headers.CorrelationId, out var correlationId) && correlationId != null) { newCorrelationId = newCorrelationId.AppendTLV("id", correlationId); } @@ -92,7 +92,7 @@ protected void AddTraceHeadersForRoutingBackReply(BaseForwardRuleContext context /// static void UnwrapCorrelationIdAndSetTraceHeader(BaseForwardRuleContext context) { - if (context.ForwardedHeaders.TryGetValue(Headers.CorrelationId, out var correlationId)) + if (context.ForwardedHeaders.TryGetValue(Headers.CorrelationId, out var correlationId) && correlationId != null) { while (true) { diff --git a/src/NServiceBus.Router/Pipeline/Prerouting/ReplyPreroutingTerminator.cs b/src/NServiceBus.Router/Pipeline/Prerouting/ReplyPreroutingTerminator.cs index 231a465..cd797f8 100644 --- a/src/NServiceBus.Router/Pipeline/Prerouting/ReplyPreroutingTerminator.cs +++ b/src/NServiceBus.Router/Pipeline/Prerouting/ReplyPreroutingTerminator.cs @@ -22,10 +22,11 @@ static string InterfaceForReply(ReplyPreroutingContext context) string destinationIface = null; if (!context.Headers.TryGetValue(RouterHeaders.ReplyToTrace, out var replyToTrace) - && !context.Headers.TryGetValue(Headers.CorrelationId, out replyToTrace)) + && (!context.Headers.TryGetValue(Headers.CorrelationId, out replyToTrace) || replyToTrace is null)) { throw new UnforwardableMessageException($"The reply has to contain either '{Headers.CorrelationId}' header set by the sending endpoint or '{RouterHeaders.ReplyToTrace}' set by the replying endpoint in order to be routed."); } + try { replyToTrace.DecodeTLV((t, v) => diff --git a/src/NServiceBus.Router/TypeLengthValueDecoder.cs b/src/NServiceBus.Router/TypeLengthValueDecoder.cs index a8e836c..6732113 100644 --- a/src/NServiceBus.Router/TypeLengthValueDecoder.cs +++ b/src/NServiceBus.Router/TypeLengthValueDecoder.cs @@ -14,6 +14,11 @@ public static string AppendTLV(this string existingTLV, string type, string valu public static bool TryDecodeTLV(this string tlvString, Action valueCallback) { + if (tlvString is null) + { + return false; + } + var remaining = tlvString; while (true) {