8000 NullReferenceException in timing.cs · Issue #70 · MiniProfiler/dotnet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
NullReferenceException in timing.cs #70
Closed
@bradtwurst

Description

@bradtwurst

using miniprofiler in a non-mvc environment to capture sql timings

MiniProfiler.Settings.ProfilerProvider = new SingletonProfilerProvider();

var cn = new ProfiledDbConnection(new OleDbConnection(config.IssuesDbConn), MiniProfiler.Current);

using Parallel.Invoke method to perform multiple methods against a group of databases (currently three different methods are running in parallel)

Occasionally receive a NRE in the GetCustomTimingList() method.

    private List<CustomTiming> GetCustomTimingList(string category)
    {
       if (CustomTimings == null)
            CustomTimings = new Dictionary<string, List<CustomTiming>>();

        List<CustomTiming> result;
        lock (CustomTimings)
        {
            if (!CustomTimings.TryGetValue(category, out result))
            {
                result = new List<CustomTiming>();
                CustomTimings[category] = result;
            }
        }
        return result;

I think what is happening is that there is a race condition between the time CustomTimings is checked for existence and the instant when it is created.

If I put a lock around the initial if statement, I haven't encountered the NRE (yet).

Also, the code in this method may lose information in a concurrent environment. a decent explanation is at http://mortoray.com/2012/02/28/double-checked-locking-why-doesnt-it-work-and-how-to-fix-it/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0