Skip to content

Commit

Permalink
Merge pull request #34 from sillsdev/null-guard
Browse files Browse the repository at this point in the history
Null-guard Shutdown method (BL-12617)
  • Loading branch information
andrew-polk authored Aug 29, 2023
2 parents 709c0f3 + 33038b1 commit d01d108
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/DesktopAnalytics/SegmentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ public void ShutDown()
// So instead of calling Flush, if there are events in the queue, we just wait a little while.
// The default timeout on the client is 5 seconds, so probably we should never need to wait
// longer than that.
var stats = Segment.Analytics.Client.Statistics;
int totalWait = 0;
var stats = Segment.Analytics.Client?.Statistics;

// Apparently, Segment.Analytics.Client can already be null at this point.
if (stats == null)
return;

int totalWait = 0;
while (stats.Submitted > stats.Failed + stats.Succeeded)
{
if (totalWait > 7500)
Expand All @@ -62,7 +67,7 @@ public void ShutDown()
Thread.Sleep(500);
}
//Client.Flush();
Segment.Analytics.Client.Dispose();
Segment.Analytics.Client?.Dispose();
}
public void Identify(string analyticsId, Traits traits, Options options)
{
Expand Down

0 comments on commit d01d108

Please sign in to comment.