csainty / Glimpse.RavenDb

RavenDb Profiling plugin for Glimpse
http://csainty.github.com/Glimpse.RavenDb
MIT License
8 stars 9 forks source link

NullReferenceException when executing a query.ToList() #10

Open karlcassar opened 10 years ago

karlcassar commented 10 years ago

This is related to the Glimpse.RavenDb.Profiler. When I execute a particular query, I get the below error.

        An exception of type 'System.NullReferenceException' occurred in Glimpse.AspNet.dll but was not handled in user code

        Additional information: Object reference not set to an instance of an object.
       at Glimpse.AspNet.AspNetFrameworkProvider.get_HttpRequestStore()
       at Glimpse.Core.Framework.Factory.<>c__DisplayClass2.<InstantiateTimerStrategy>b__1()
       at Glimpse.RavenDb.Profiler.DurationOnTimeline(String message, DateTime startTime, TimeSpan duration) in c:\Projects\Glimpse.RavenDb\Glimpse.RavenDb\Profiler.cs:line 112
       at Glimpse.RavenDb.Profiler.EndRequest(Object sender, RequestResultArgs e) in c:\Projects\Glimpse.RavenDb\Glimpse.RavenDb\Profiler.cs:line 92
       at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
       at Raven.Client.Connection.HttpJsonRequestFactory.InvokeLogRequest(IHoldProfilingInformation sender, Func`1 generateRequestResult)
       at Raven.Client.Connection.HttpJsonRequest.ReadJsonInternal(Func`1 getResponse)
       at Raven.Client.Connection.HttpJsonRequest.ReadResponseJson()
       at Raven.Client.Connection.ServerClient.DirectQuery(String index, IndexQuery query, OperationMetadata operationMetadata, String[] includes, Boolean metadataOnly, Boolean includeEntries)
       at Raven.Client.Connection.ServerClient.<>c__DisplayClass62.<Query>b__61(OperationMetadata u)
       at Raven.Client.Connection.ReplicationInformer.TryOperation[T](Func`2 operation, OperationMetadata operationMetadata, OperationMetadata primaryOperationMetadata, Boolean avoidThrowing, T& result, Boolean& wasTimeout)

Not much more clue is given - any idea what is wrong? Is this a bug in the profiler? If I switch off the RavenDB profiler, it works fine so I'm assuming it is.

Feel free to ask for further information to replicate the issue, and I will provide.

Kind Regards, Karl

csainty commented 10 years ago

Is this an async query or otherwise performed on another thread?

In that case, due to the architecture of Glimpse v1, when it tries to write the timeline message it dies because it can not find HttpContext.Current. Glimpse v2 is built in a way that should remove this sort of problem, in the mean time the plugin could do some try/catch to swallow the problem, but then you'd be confused by the lack of results.

So I don't have a great solution for this at the moment sorry.