Skip to content

Commit

Permalink
Pull request #258: RUM-17682 Improve leave action
Browse files Browse the repository at this point in the history
Merge in OP/openkit-dotnet from feature/RUM-17682-openkit-.net-release-3.2.1 to main

* commit 'b866ba301b04f064401292ff93a95139d3e8e97e':
  RUM-17682 Removing null check
  RUM-17682 Locking other GetCopyOfChildObjects
  RUM-17682 Move loop out
  RUM-17682 Improve leave action

GitOrigin-RevId: 2c045cca91f4857862afa2514217af4b86f1600b
  • Loading branch information
TheHighriser authored and openkitdt committed Jan 30, 2024
1 parent 76e9c10 commit a472f11
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changed

- `HttpClientWebClient` for NET3.5 is now using User-Agent property directly
- Improved cancelation or disposal of childs when leaving an action

## 3.2.0 [Release date: 2023-12-06]
[GitHub Releases](https://github.com/Dynatrace/openkit-dotnet/releases/tag/v3.2.0)
Expand Down
10 changes: 7 additions & 3 deletions src/Dynatrace.OpenKit/Core/Objects/BaseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Dynatrace.OpenKit.Protocol;
using Dynatrace.OpenKit.Util;
using System;
using System.Collections.Generic;

namespace Dynatrace.OpenKit.Core.Objects
{
Expand Down Expand Up @@ -376,6 +377,8 @@ public IAction CancelAction()

private IAction DoLeaveAction(bool discardData)
{
IList<IOpenKitObject> childObjects;

lock (LockObject)
{
if (ThisAction.IsActionLeft)
Expand All @@ -385,9 +388,10 @@ private IAction DoLeaveAction(bool discardData)
}

isActionLeft = true;
}

var childObjects = ThisComposite.GetCopyOfChildObjects();
childObjects = ThisComposite.GetCopyOfChildObjects();
}

foreach (var childObject in childObjects)
{
if (discardData)
Expand All @@ -407,7 +411,7 @@ private IAction DoLeaveAction(bool discardData)
childObject.Dispose();
}
}

EndTime = Beacon.CurrentTimestamp;
EndSequenceNo = Beacon.NextSequenceNumber;

Expand Down
6 changes: 5 additions & 1 deletion src/Dynatrace.OpenKit/Core/Objects/OpenKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//

using System;
using System.Collections.Generic;
using Dynatrace.OpenKit.API;
using Dynatrace.OpenKit.Core.Caching;
using Dynatrace.OpenKit.Core.Configuration;
Expand Down Expand Up @@ -214,6 +215,8 @@ public void Shutdown()
logger.Debug($"{GetType().Name} shutdown requested");
}

IList<IOpenKitObject> childObjects;

lock (lockObject)
{
if (isShutdown)
Expand All @@ -222,10 +225,11 @@ public void Shutdown()
}

isShutdown = true;

childObjects = ThisComposite.GetCopyOfChildObjects();
}

// close all open children
var childObjects = ThisComposite.GetCopyOfChildObjects();
foreach (var childObject in childObjects)
{
childObject.Dispose();
Expand Down
10 changes: 8 additions & 2 deletions src/Dynatrace.OpenKit/Core/Objects/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,18 @@ public void End(bool sendSessionEndEvent)
// forcefully leave all child elements
// Since the end time was set, no further child objects are added to the internal list so the following
// operations are safe outside the lock block.
var childObjects = ThisComposite.GetCopyOfChildObjects();
IList<IOpenKitObject> childObjects;

lock (state)
{
childObjects = ThisComposite.GetCopyOfChildObjects();
}

foreach (var childObject in childObjects)
{
childObject.Dispose();
}

// send the end event, only if a session is explicitly ended
if (sendSessionEndEvent)
{
Expand Down
7 changes: 5 additions & 2 deletions src/Dynatrace.OpenKit/Core/Objects/SessionProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ public void End()
logger.Debug($"{this} End()");
}

IList<IOpenKitObject> childObjects;

lock (lockObject)
{
if (isFinished)
Expand All @@ -392,9 +394,10 @@ public void End()
}

isFinished = true;

childObjects = ThisComposite.GetCopyOfChildObjects();
}

var childObjects = ThisComposite.GetCopyOfChildObjects();
foreach (var childObject in childObjects)
{
if (childObject is ISessionInternals childSession)
Expand All @@ -406,7 +409,7 @@ public void End()
childObject.Dispose();
}
}

parent.OnChildClosed(this);
sessionWatchdog.RemoveFromSplitByTimeout(this);
}
Expand Down

0 comments on commit a472f11

Please sign in to comment.