[Mono-bugs] [Bug 58558][Blo] Changed - static constructors don't get called

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 18 May 2004 06:44:32 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by jaak@zd.com.pl.

http://bugzilla.ximian.com/show_bug.cgi?id=58558

--- shadow/58558	2004-05-17 18:50:16.000000000 -0400
+++ shadow/58558.tmp.22183	2004-05-18 06:44:32.000000000 -0400
@@ -127,6 +127,96 @@
 +                                       instance = new DefaultConfig ();
 +                       }
 +
                         return instance;
                 }
 -------------
+
+------- Additional Comments From jaak@zd.com.pl  2004-05-18 06:44 -------
+Another piece of evidence which seems to be related to this problem:
+
+-----------------
+using System;
+using System.Net;
+
+public class A : MarshalByRefObject
+{
+ public void test()
+ {
+  Console.WriteLine("ccc");
+  Dns.GetHostByName("localhost");
+  Console.WriteLine("ddd");
+ }
+ public static void Main()
+ {
+  Console.WriteLine("aaa");
+  Dns.GetHostByName("localhost");
+  Console.WriteLine("bbb");
+  AppDomain domain = AppDomain.CreateDomain("aaa");
+  A a = (A)domain.CreateInstanceAndUnwrap(typeof(A).Assembly.FullName,
+typeof(A).FullName);
+  a.test();
+ }
+}
+-------------
+
+This code behaves in a wild way on my system (I compiled it into
+a.exe. In addition I've put a diagnostic message in System.Net/Dns.cctor):
+
+1. "mono a.exe" - prints out the following but hangs in 30% cases.
+
+==========
+aaa
+System.Net.Dns.cctor called in a.exe
+bbb
+ccc
+System.Net.Dns.cctor called in aaa
+ddd
+==========
+
+I once managed to get it to throw NullRef exception in some random run.
+
+2. "mono --optimize=shared a.exe" prints out (100% cases):
+
+==========
+aaa
+System.Net.Dns.cctor called in a.exe
+bbb
+ccc
+
+Unhandled Exception: System.NullReferenceException: Object reference
+not set to an instance of an object
+
+Server stack trace: 
+in (unmanaged) /opt/mono/lib/libmono.so.0 [0x87a090]
+in (unmanaged) /opt/mono/lib/libmono.so.0 [0x87a468]
+in <0x0002d> (wrapper managed-to-native)
+System.Net.Dns:GetHostByName_internal (string,string&,string[]&,string[]&)
+in <0x00063> System.Net.Dns:GetHostByName (string)
+in <0x00044> A:test ()
+in (unmanaged) /opt/mono/lib/libmono.so.0 [0x819b29]
+in (unmanaged) /opt/mono/lib/libmono.so.0(mono_runtime_invoke+0x23)
+[0x8585ef]
+in (unmanaged)
+/opt/mono/lib/libmono.so.0(mono_runtime_invoke_array+0x125) [0x859335]
+in (unmanaged) /opt/mono/lib/libmono.so.0 [0x85f522]
+in <0x0017f>
+System.Runtime.Remoting.RemotingServices:InternalExecuteMessage
+(System.MarshalByRefObject,System.Runtime.Remoting.Messaging.IMethodCallMessage)
+
+
+Exception rethrown at [0]: 
+
+in <0x0020a> System.Runtime.Remoting.Proxies.RealProxy:PrivateInvoke
+(System.Runtime.Remoting.Proxies.RealProxy,System.Runtime.Remoting.Messaging.IMessage,System.Exception&,object[]&)
+
+==========
+
+As far as I understand it there should be "System.Net.Dns.cctor called
+in aaa" immediately following "ccc" and BEFORE a call to
+GetHostByName() but there isn't.
+
+Note that the problems only appear within child appdomains. Looks like
+a big race condition or memory corruption. 
+
+FYI: I have MONO_NO_UNLOAD set so that AppDomain.Unload doesn't crash
+my applications.