Skip to content

Commit

Permalink
Fixed issue AttackPattern#33 where multiple apps startup causes excep…
Browse files Browse the repository at this point in the history
…tion to be thrown due to multiple session saving race.
  • Loading branch information
JimiC committed Oct 22, 2015
1 parent 3580185 commit d3bc8fc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Source/CSharpAnalytics/AutoMeasurement/BaseAutoMeasurement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ public async void Start(MeasurementConfiguration configuration, string launchKin
sessionManager = new SessionManager(sessionState, configuration.SampleRate);
await StartRequesterAsync();

if (delayedOptOut != null) SetOptOut(delayedOptOut.Value);
// Preserve 'delayedOptOut' value to use in condition checking
var hasDelayedOptOut = delayedOptOut;
if (hasDelayedOptOut.HasValue) SetOptOut(delayedOptOut.GetValueOrDefault());

This comment has been minimized.

Copy link
@xmedeko

xmedeko Oct 22, 2015

Should be SetOptOut(hasDelayedOptOut.Value)?

This comment has been minimized.

Copy link
@JimiC

JimiC Oct 22, 2015

Author Owner

Could be but I have preserved the usage of 'delayedOptOut' as it's the actual value set by the user. 'hasDelayedOptOut' is only added and used for condition checking as 'delayedOptOut ' gets nullified in 'SetOptOut'.


Client.Configure(configuration, sessionManager, GetEnvironment(), Add);

// Sometimes apps crash so preserve at least session number and visitor id on launch
await Save(sessionManager.GetState(), SessionStorageName);
// Avoid re-saving if a delayed optout was set (save already occurred in 'SetOptOut')
if (!hasDelayedOptOut.HasValue)
await Save(sessionManager.GetState(), SessionStorageName);

HookEvents();
}
Expand Down

0 comments on commit d3bc8fc

Please sign in to comment.