Bug 325507 (MONO82840) - Unhandled exception changes make xsp2 quit
Summary: Unhandled exception changes make xsp2 quit
Status: RESOLVED FIXED
Alias: MONO82840
Product: Mono: Runtime
Classification: Mono
Component: JIT (show other bugs)
Version: unspecified
Hardware: Other Linux
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Massimiliano Mantione
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-13 20:12 UTC by Daniel Nauck
Modified: 2007-09-19 19:10 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 20:53:43 UTC


---- Reported by dna@informatik.uni-kiel.de 2007-09-13 13:12:59 MST ----

Using version 1.2.5 (/trunk/ r85727).

Xsp2 quits without any error message when serving a ASP.NET page with a
Ajax Script Service. (Like the AjaxControlToolkit SlideShowExtender Samplepage)

If i add a xsp2.exe.config to xsp2.exe with the content:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <runtime>
     <legacyUnhandledExceptionPolicy enabled="1"/>
   </runtime>
</configuration>

the problem is gone.



---- Additional Comments From massi@ximian.com 2007-09-13 15:43:16 MST ----

Thinking about it, this seems the intended behavior.

In .NET 1.1, unhandled exceptions kill the thread and are ignored.
In .NET 2.0 (xsp2), they kill the while process, unless you specify
you want the legacy behavior.
So, I'm almost sure there's an unhandled exception somewhere...

Please add an "unhandled exception handler" to the root appdomain,
and-or to the appdomain involved in the problem (the event is
"UnhandledException", and the root appdomain would be better (its
handler is called in any case).
This will give you a chance to print the exception (inside the
handler).



---- Additional Comments From mhabersack@novell.com 2007-09-13 19:34:57 MST ----

Maybe this article will shed some light -
http://www.eggheadcafe.com/articles/20060305.asp



---- Additional Comments From dna@informatik.uni-kiel.de 2007-09-14 04:14:29 MST ----

First i tested the:
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

handler in Application_Start of my Global.asax. The handler loggs the
exception into log4net and prints it to the console.
But xsp2 quits without any message.

Then i tested the UnhandledExceptionHttpModule solution. Same result.

I enabled heavy logging in my application and it turns out, that it
happens every time i'm using:
Activator.CreateInstance("Npgsql", "Npgsql.NpgsqlConnection").Unwrap()

(the latest logentry is short before that instruction)

As far as i can say i dont had this problem on tuesday with r85628.



---- Additional Comments From massi@ximian.com 2007-09-14 05:30:58 MST ----

Could it be that this statement:
Activator.CreateInstance("Npgsql", "Npgsql.NpgsqlConnection").Unwrap()
actually causes the execution of code in a different thread, which in
turn throws an unhandled exception?

Try invoking xsp2 under gdb, and give Mono the --breakonex argument.
See here "http://www.mono-project.com/Debugging" for help on gdb
usage with Mono.
Or try --trace, but expect a *huge* log!

Ideally, you should see where the exception is thrown... if other
exceptions are thrown before, just "cont"...

Otherwise, post the smallest app which shows the problem, and let
me see if that's the issue.


Unknown bug field "cf_op_sys_details" encountered while moving bug
   <cf_op_sys_details>Ubuntu feisty</cf_op_sys_details>

Comment 1 Daniel Nauck 2007-09-18 11:46:29 UTC
I applied Massi's patch to print out the exception:

Index: mono/metadata/object.c
===================================================================
--- mono/metadata/object.c      (Revision 85796)
+++ mono/metadata/object.c      (Arbeitskopie)
@@ -2754,6 +2754,14 @@
                        }
                }
        }
+       if (mono_thread_current () == mono_thread_get_main ()) {
+               printf ("mono_thread_current () == mono_thread_get_main (): true\n");
+       } else {
+                printf ("mono_thread_current () == mono_thread_get_main (): false\n");
+       }
+
+       printf ("Examining unhandled exception\n");
+       mono_print_unhandled_exception (exc);
 }

 /*


The Result is:

Hit Return to stop the server.
mono_thread_current () == mono_thread_get_main (): false
Examining unhandled exception

Unhandled Exception: System.Threading.ThreadAbortException: Thread was being aborted
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_thread_interruption_checkpoint ()
  at (wrapper managed-to-native) System.Threading.WaitHandle:WaitOne_internal (intptr,int,bool)
  at System.Threading.WaitHandle.WaitOne (Int32 millisecondsTimeout, Boolean exitContext) [0x00020] in /home/dna/mono-svn/mcs/class/corlib/System.Threading/WaitHandle.cs:314 
  at System.Threading.Timer+Runner.Start () [0x0008b] in /home/dna/mono-svn/mcs/class/corlib/System.Threading/Timer.cs:140 
  at (wrapper delegate-invoke) System.MulticastDelegate:invoke_void ()
Comment 2 Daniel Nauck 2007-09-18 12:49:53 UTC
Patch from Massi:

Index: mono/mini/mini.c
===================================================================
--- mono/mini/mini.c    (Revision 85966)
+++ mono/mini/mini.c    (Arbeitskopie)
@@ -8927,7 +8927,8 @@
        /* handle_remove should be eventually called for this thread, too
        g_free (jit_tls);*/

-       if (mono_runtime_unhandled_exception_policy_get () == MONO_UNHANLED_POLICY_LEGACY) {
+       if ((mono_runtime_unhandled_exception_policy_get () == MONO_UNHANLED_POLICY_LEGACY) ||
+       (obj->vtable->klass == mono_defaults.threadabortexception_class)) {
                mono_thread_exit ();
        } else {
                exit (mono_environment_exitcode_get ());
Comment 3 Massimiliano Mantione 2007-09-19 14:44:44 UTC
Fixed in svn, r86014.
Comment 4 Jan Oravec 2007-09-19 17:56:16 UTC
There is a typo in r86014 patch. It should be '==' instead of '!='.

--- mono/mini/mini.c    (revision 86023)
+++ mono/mini/mini.c    (working copy)
@@ -8928,7 +8928,7 @@
        g_free (jit_tls);*/
 
        if ((mono_runtime_unhandled_exception_policy_get () == MONO_UNHANLED_POLICY_LEGACY) ||
-                       (obj->vtable->klass != mono_defaults.threadabortexception_class)) {
+                       (obj->vtable->klass == mono_defaults.threadabortexception_class)) {
                mono_thread_exit ();
        } else {
                exit (mono_environment_exitcode_get ());
Comment 5 Daniel Nauck 2007-09-19 19:10:32 UTC
Fixed in svn r86030.

Thanks.