0

I have an Asp .Net application for which I'm using the new async/await paradigm with .net 4.5 RC. I am using the new task-based async http handler HttpTaskAsyncHandler for handling http request. In my code i'm doing some I/O streaming a file to the client.

once in a while i'm getting a NullPointerException with the following stack trace:

System.Web.dll!System.Web.HttpApplication.CurrentModuleContainer.get() + 0x1e bytes System.Web.dll!System.Web.HttpApplication.PipelineStepManager.ResumeSteps(System.Exception error) + 0xb7 bytes
System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(System.IAsyncResult ar) + 0x1f3 bytes
mscorlib.dll!System.Threading.Tasks.Task.Execute() + 0x6e bytes mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x285 bytes mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x9 bytes
mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) + 0x1c5 bytes
mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) + 0xb0 bytes
mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x1ea bytes
[Native to Managed Transition]
[Appdomain Transition]
[Native to Managed Transition]

This seems to happen after my code already returned the response.

When this happens the next request is just never handled, but the one after it is back to normal.

What could be the reason for this behavior? I took a peek at the source code for the CurrentModuleContainer.Get method and it seems that the only thing that can throw a null pointer exception is the Http context.

rony l
  • 5,152
  • 4
  • 31
  • 52
  • Can't help without the code, although a NullReferenceException means you tried to use a variable that is null. – Panagiotis Kanavos Jul 15 '12 at 17:44
  • Did you ever figure this out? I'm seeing the same thing. See here: http://stackoverflow.com/questions/33698395/unobservedtaskexception-where-did-the-task-come-from – dmarlow Dec 02 '15 at 16:30

1 Answers1

0

The exception could come from many different reasons but one could guess that you are trying to access the current HttpContext in your handler, which might be null during async end function.

Julien Jacobs
  • 2,381
  • 1
  • 21
  • 32