Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException in timing.cs #70

Closed
bradtwurst opened this issue May 30, 2014 · 3 comments
Closed

NullReferenceException in timing.cs #70

bradtwurst opened this issue May 30, 2014 · 3 comments
Labels

Comments

@bradtwurst
Copy link
Contributor

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/

@yellis yellis added the bug label Jun 1, 2014
@yellis
Copy link
Member

yellis commented Jun 1, 2014

Thanks for reporting this.

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

Would you like to submit this as a PR?

@yellis
Copy link
Member

yellis commented Jun 11, 2014

Closing as #75 has been merged

@yellis yellis closed this as completed Jun 11, 2014
@yellis
Copy link
Member

yellis commented Jun 11, 2014

This has been included in v3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants