nobitagamer / elmah

Automatically exported from code.google.com/p/elmah
Apache License 2.0
0 stars 0 forks source link

SQL Logging mode crashes on Download CSV Log file - NullReferenceException (MVC3) #338

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create the universe and all living things, computers, etc.
2. Create a default empty MVC3 app
3. Install Elmah.MVC via nuget (Install-Package Elmah.MVC)
4. Configure <errorLog> element to use SqlErrorLog
5. Run/Debug the solution (no controllers in the soln will cause a quick 404 
error)
6. Navigate to /elmah
7. Click the “Download Log” link

I attached a basic VS2010 solution to this DR that should demonstrate this 
issue.  Only thing that should be needed is a valid SQL connection string in 
the web.config, but don't quote me on that.

What is the expected output? What do you see instead?

Expected the log to be downloaded fully as a CSV file. Instead, crashes IIS 
worker processes with this stack trace:

Unhandled Exception: System.NullReferenceException: Object reference not set to 
an instance of an object.
   at Elmah.ErrorLogDownloadHandler.GetErrorsCallback(IAsyncResult result)
   at Elmah.SqlErrorLog.<>c__DisplayClass3.<BeginGetErrors>b__1(IAsyncResult )
   at System.Data.Common.DbAsyncResult.AsyncCallback_Context(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Data.Common.DbAsyncResult.ExecuteCallback(Object asyncResult)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

This was tested on the following server types:
- Default ASP.NET Cassini
- IIS Express 7.5
- IIS 7.0

ELMAH version is 1.2.14706.955.

Can anyone confirm if this is also an issue for them?

Original issue reported on code.google.com by kir...@gmail.com on 18 Jul 2013 at 3:58

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for reporting this issue with detail and a sample to demonstrate it. I 
have been able to reproduce the issue with the combination of ELMAH 1.2 SP 2 
and Elmah.MVC. Below is the full stack trace with line numbers:

   at Elmah.ErrorLogDownloadHandler.AsyncResult.End() in c:\builds\ELMAH-1.2-SP2\src\Elmah\ErrorLogDownloadHandler.cs:line 534
   at Elmah.ErrorLogDownloadHandler.EndProcessRequest(IAsyncResult result) in c:\builds\ELMAH-1.2-SP2\src\Elmah\ErrorLogDownloadHandler.cs:line 138
   at Elmah.ErrorLogDownloadHandler.ProcessRequest(HttpContext context) in c:\builds\ELMAH-1.2-SP2\src\Elmah\ErrorLogDownloadHandler.cs:line 61
   at Elmah.Mvc.ElmahResult.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)

ELMAH 1.2 SP 2, package version 1.2.1 and file version 1.2.14706.955
Elmah.MVC package version 2.1.1 and assembly version 2.0.0.29988

I will post more details and possibly a workaround later.

Original comment by azizatif on 19 Jul 2013 at 5:53

GoogleCodeExporter commented 8 years ago
This issue occurs due to an erroneous race condition under a very specific set 
of circumstances, when ELMAH is used in combination with Elmah.MVC and 
SqlErrorLog and only when downloading the log.

SqlErrorLog is the only ErrorLog implementation supplied with ELMAH that 
supports asynchronous operations. ErrorLogDownloadHandler is the only HTTP 
handler in ELMAH that is implemented to take advantage of asynchronous 
operations of an ErrorLog implementation in order to avoid tying a worker 
thread due to I/O latency (especially in production). Elmah.MVC on the other 
hand forces synchronous processing by invoking 
ErrorLogDownloadHandler.ProcessRequest[1], which is where the race condition 
occurs. Unfortunately, this code path never gets invoked by ASP.NET directly 
because if a handler implements IHttpAsyncHandler then BeginProcessRequest and 
EndProcessRequest are always called in lieu of ProcessRequest, even if the 
downstream ErrorLog implementation natively support asynchronous operation or 
not.

Given the above, there are a number of workarounds possible:

1. Remove Elmah.MVC and just use ELMAH. You really do not need the former.
2. Log an issue with Elmah.MVC project to use asynchronous operations of a 
handler where available. This is a good thing anyhow as you do not want to 
reduce your server scalability due to operational management.
3. Do not use the SqlErrorLog but same scalability concern as in vein 2.
4. Subclass SqlErrorLog and revert asynchronous implementation but same 
scalability concern as in vein 2.

Since there is no plan for an SP 3 and you still wish to use Elmah.MVC, you 
might want to consider avenue 2 as the quickest resolution.

[1] 
https://github.com/alexanderbeletsky/elmah-mvc/blob/ad954deb50efd42302b18a61eb87
a2661a4ffdd2/src/Elmah.Mvc/ElmahResult.cs#L68

Original comment by azizatif on 19 Jul 2013 at 7:15

GoogleCodeExporter commented 8 years ago

Original comment by azizatif on 19 Jul 2013 at 4:39

GoogleCodeExporter commented 8 years ago
This issue was closed by revision 7576b913e220.

Original comment by azizatif on 19 Jul 2013 at 5:02

GoogleCodeExporter commented 8 years ago
There is no plan to make a NuGet release with this fix so patched binaries are 
being attached here as a convenience.

Original comment by azizatif on 19 Jul 2013 at 5:07

Attachments: