Navigation Menu

Skip to content

Commit

Permalink
Ensure copies of mutable data
Browse files Browse the repository at this point in the history
These dictionaries can be mutated while we are performing serialisation so we need to ensure that we are only working on copies of the data
  • Loading branch information
martin308 committed Aug 1, 2018
1 parent bdf2cec commit 1926978
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/BugsnagUnity/IClient.cs
Expand Up @@ -113,11 +113,12 @@ void Notify(string condition, string stackTrace, LogType logType)
{
if (LogTypeCounter.ShouldSend(logMessage))
{
var user = new User { Id = User.Id, Email = User.Email, Name = User.Name };
var @event = new Payload.Event(Configuration.Context,
GenerateMetadata(),
GenerateAppData(),
GenerateDeviceData(),
User,
user,
new UnityLogExceptions(logMessage).ToArray(),
HandledState.ForHandledException(),
Breadcrumbs.Retrieve(), SessionTracking.CurrentSession,
Expand Down Expand Up @@ -167,11 +168,12 @@ public void Notify(System.Exception exception, Severity severity, Middleware cal

void Notify(System.Exception exception, HandledState handledState, Middleware callback)
{
var user = new User { Id = User.Id, Email = User.Email, Name = User.Name };
var @event = new Payload.Event(Configuration.Context,
GenerateMetadata(),
GenerateAppData(),
GenerateDeviceData(),
User,
user,
new Exceptions(exception).ToArray(),
handledState,
Breadcrumbs.Retrieve(),
Expand Down
12 changes: 12 additions & 0 deletions src/BugsnagUnity/Payload/Session.cs
Expand Up @@ -34,6 +34,15 @@ internal void AddException(Report report)
Events.IncrementUnhandledCount();
}
}

internal Session Copy()
{
var copy = new Session(StartedAt, Events.Handled, Events.Unhandled)
{
["id"] = Id
};
return copy;
}
}

internal class SessionEvents : Dictionary<string, int>
Expand All @@ -47,6 +56,9 @@ internal SessionEvents(int handled, int unhandled)
this.AddToPayload("unhandled", unhandled);
}

internal int Handled => this["handled"];
internal int Unhandled => this["unhandled"];

internal void IncrementHandledCount()
{
lock (_handledLock)
Expand Down
8 changes: 7 additions & 1 deletion src/BugsnagUnity/SessionTracker.cs
Expand Up @@ -13,7 +13,13 @@ class SessionTracker : ISessionTracker
{
private IClient Client { get; }

public Session CurrentSession { get; private set; }
private Session _currentSession;

public Session CurrentSession
{
get => _currentSession.Copy();
private set => _currentSession = value;
}

internal SessionTracker(IClient client)
{
Expand Down

0 comments on commit 1926978

Please sign in to comment.