Skip to content

Commit

Permalink
Protect against NullReferenceExceptions when Load() returns a null pr…
Browse files Browse the repository at this point in the history
…ofiler

There is a race condition where getting the list of profiler GUIDs would return a valid id but then loading the profiler by id it might not exist. This causes NullRefereneceExceptions. For example, we have our own Redis storage implementation where profilers automatically expire after a specified timeout.

So, depending on the storage, profilers might not exist by id and this protects against that.
  • Loading branch information
TheCloudlessSky authored Jun 16, 2016
1 parent 18daa31 commit c51c3ad
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion StackExchange.Profiling/MiniProfilerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ private static string GetListJson(HttpContext context)
g =>
{
var profiler = MiniProfiler.Settings.Storage.Load(g);

if (profiler == null)
{
return null;
}

return new
{
profiler.Id,
Expand All @@ -271,7 +277,7 @@ private static string GetListJson(HttpContext context)
profiler.User,
profiler.DurationMilliseconds
};
}).ToJson();
}).Where(x => x != null).ToJson();
}

/// <summary>
Expand Down

0 comments on commit c51c3ad

Please sign in to comment.