Skip to content

Commit 69fa830

Browse files
Fix NullReferenceException in Rabbit. (#7083)
## Summary of changes We are getting [the following](https://ddstaging.datadoghq.com/error-tracking?query=source%3Adotnet%20-%2AOutOfMemoryException%2A%20%40tracer_version%3A3.18%2A&refresh_mode=sliding&source=all&sp=%5B%7B%22p%22%3A%7B%22issueId%22%3A%22ddffb7a6-3d7b-11f0-b08f-da7ad0900002%22%7D%2C%22i%22%3A%22error-tracking-issue%22%7D%5D&from_ts=1748947778182&to_ts=1749552578182&live=true) NullReferenceException. ``` Error : Exception occurred when calling the CallTarget integration continuation. System.NullReferenceException at Datadog.Trace.ClrProfiler.AutoInstrumentation.RabbitMQ.PopulateBasicPropertiesHeadersIntegration.OnMethodEnd[TTarget,TReturn](TTarget instance, TReturn returnValue, Exception exception, CallTargetState& state) at RabbitMQ.Client.Impl.Channel.PopulateBasicPropertiesHeaders[TProperties](TProperties basicProperties, Activity sendActivity, UInt64 publishSequenceNumber) ``` We can reproduce the issue with the following code: ``` BasicProperties property = default; -> NULL var duckType = property.DuckCast<IBasicProperties>()!; -> duckType = NULL duckType.Headers ??= new Dictionary<string, object>(); -> NullReferenceException ``` ## Reason for change ## Implementation details ## Test coverage ## Other details <!-- Fixes #{issue} --> <!-- ⚠️ Note: where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. -->
1 parent 31cd314 commit 69fa830

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ/PopulateBasicPropertiesHeadersIntegration.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal static CallTargetState OnMethodBegin<TTarget, TBasicProperties, TActivi
5454
}
5555

5656
// TReturn is type RabbitMQ.Client.BasicProperties
57-
TReturn? basicProperties = default;
57+
TReturn? basicProperties;
5858

5959
// PopulateBasicPropertiesHeaders returns null if the supplied IReadOnlyBasicProperties
6060
// does not have to be modified or if it's a writable instance.
@@ -80,6 +80,10 @@ internal static CallTargetState OnMethodBegin<TTarget, TBasicProperties, TActivi
8080
basicProperties = CachedBasicPropertiesHelper<TReturn>.CreateHeaders(state.State!);
8181
}
8282
}
83+
else
84+
{
85+
basicProperties = returnValue;
86+
}
8387

8488
// duck cast so we can access the Headers property
8589
var duckType = basicProperties.DuckCast<IBasicProperties>()!;

0 commit comments

Comments
 (0)