Dynatrace / openkit-dotnet

OpenKit .NET Reference Implementation
Apache License 2.0
16 stars 16 forks source link

User session crash on DoLeaveAction(Boolean discardData) #123

Open BTony95 opened 10 months ago

BTony95 commented 10 months ago

Describe the bug We run a C# application where we use Dynatrace as a logging/tracing system. We have noticed that some users experience a crash with stacktrace below without any clue why this happens.

To Reproduce The crash appears at random and we can't force a reproduce unfortunately.

Expected behavior We do not expect a user session to crash by this issue. We want to be able to handle this issue in the background without any issues seen by the enduser

Stacktrace (Slightly redacted)

Exception information


ThreadIdentity: ClaimsPrincipal: UserName: XXXXXXX

1) System.NullReferenceException Message: Object reference not set to an instance of an object. HResult: 80004003 Data: System.Object:

StackTrace at Dynatrace.OpenKit.Core.Objects.BaseAction.DoLeaveAction(Boolean discardData) at Dynatrace.OpenKit.Core.Objects.BaseAction.LeaveAction() at NinjaProject.Dynatrace.Extensions.UserTrackingTelemetry.Dispose() in D:\BLD1_work\44\s\NinjaProject.Dynatrace.Extensions\Logic\UserTrackingTelemetry.cs:line 88 at System.Threading.Tasks.DynatraceTaskExtensions.d__1`1.MoveNext() in D:\BLD1_work\44\s\NinjaProject.Dynatrace.Extensions\Extensions\DynatraceTaskExtensions.cs:line 37 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

TheHighriser commented 10 months ago

Hi,

As we don't have a line number in the stacktrace, would you mind telling us which version of OpenKit .NET is used in your application?

Thanks!

BTony95 commented 10 months ago

Hello,

No line numbers were left out in the stacktrace. That is why we indeed could use your help to fix the issue. Here is a screenshot of the specifics.

image

TheHighriser commented 10 months ago

Okay so you are using the Main branch, as there is no 3.2 release. We have got an idea about the issue and will try to create a fix. I will notify you again here when work is done.

TheHighriser commented 10 months ago

Did you directly use the main branch here? Or did you add some modifications? (Stacktrace also mentions extensions?) Because I went through the whole code again and it is very hard to explain why there is a null reference.

BTony95 commented 10 months ago

We are indeed using it with a fork of the master branch.

No adjustments were made to the code on our side. The only adjustments we made was to compile with .net48 and .net7

We will try rebuilding it with the official version and configurations. Did you already find some other plausible root causes for this issue?

TheHighriser commented 10 months ago

I went through the code with some of my colleagues but we feel like it is impossible to have a NullReference in there. We first thought that the childs might contain null, but all add calls actually insert a new instance. So only beacon or parent might be an option, but also there it seems to be impossible as they get inserted in the constructor.

So the crash is still appearing constantly? So the idea of using the official version might help show us if the crash disappears?

EDIT: Do you mean .net8? Because 7 is actually added. (8 is already on the agenda)

BTony95 commented 8 months ago

Hi,

The error still occurs and one of our devs went through the code. According to him [https://github.com/Dynatrace/openkit-dotnet/blob/3836c412cb857299d956f76d5f4338bcc57807e7/src/Dynatrace.OpenKit/Core/Objects/BaseAction.cs#L390C1-L390C70] could be an explanation. A concurrent read is not locked with other writes.

Could you have a look on your side?

TheHighriser commented 8 months ago

We had internal discussions and we agree on your finding. We will enclose other calls as well into the lock (Other usages of retrieving the list of child objects). We will try to push version 3.2.1 by tomorrow.