Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Task.Factory.StartNew with uncaught Exceptions kills w3wp?

I just transitioned some of my website's code from using QueueUserWorkItem to Task.Factory.StartNew

I have some bad code that threw an Exception and it ultimately shut down w3wp. Running IIS 7.5 on Windows Server 2008 R2, x64

                Task.Factory.StartNew(() =>
                {
                    MethodThatThrowsException();
                }

Application: w3wp.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.AggregateException Stack: at System.Threading.Tasks.TaskExceptionHolder.Finalize()

Exception: System.AggregateException

Message: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.

StackTrace: at System.Threading.Tasks.TaskExceptionHolder.Finalize()

InnerException: System.Data.SqlClient.SqlException

I would have assumed an exception would have generated an event log and NOT have killed w3wp. Is this a wrong assumption?

like image 764
Visualize Avatar asked Feb 20 '11 01:02

Visualize


1 Answers

Unhandled exceptions crash IIS worker process. This is by design. http://support.microsoft.com/kb/911816

Therefore, you should properly handle exceptions.

like image 87
Lex Li Avatar answered Sep 28 '22 18:09

Lex Li