[Mono-bugs] [Bug 77468][Wis] New - usage of mono_thread_attach and mono_thread_detach cause _wapi_handle_unref warnings

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Feb 3 22:10:55 EST 2006


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 allan at imeem.com.

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

--- shadow/77468	2006-02-03 22:10:55.000000000 -0500
+++ shadow/77468.tmp.21955	2006-02-03 22:10:55.000000000 -0500
@@ -0,0 +1,92 @@
+Bug#: 77468
+Product: Mono: Runtime
+Version: 1.1
+OS: 
+OS Details: OS X 10.4.4 on G4/G5, Linux 2.6.9 (uniprocessor ia32)
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: allan at imeem.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: usage of mono_thread_attach and mono_thread_detach cause _wapi_handle_unref warnings
+
+Please fill in this template when reporting a bug, unless you know what you are doing.
+Description of Problem:
+
+Use of mono_thread_attach/mono_thread_detach cause code run from the finalizer thread to 
+generate _wapi_handle_unref warnings.
+
+According to Dick Porter (on mono-dev-list):
+"It means something in the runtime has lost track of its handles and is
+attempting to CloseHandle more times than the handle was opened.
+...
+The warning itself is harmless (the CloseHandle code ignores an unref
+attempt in these circumstances) but it is a symptom of a bug - code
+somewhere is relying on a handle that has vanished from underneath it."
+
+Steps to reproduce the problem:
+1. Run following code:
+On ia32 Linux, this code will not run long without crashing unless run against a version of Mono 
+from SVN that contains Paolo's patch for bug #77429 (http://bugs.ximian.com/show_bug.cgi?
+id=77429).
+
+#include <pthread.h>
+#include <mono/jit/jit.h>
+#include <mono/metadata/metadata.h>
+#include <mono/metadata/debug-helpers.h>
+#include <mono/metadata/object.h>
+#include <mono/metadata/threads.h>
+#include <mono/metadata/appdomain.h>
+
+#define CHUNK_THREADCOUNT 200
+
+static void *thread_function(void *monoDomain) {
+	printf("Attaching thread...\n");
+	MonoThread *monoThread = mono_thread_attach((MonoDomain *)monoDomain);
+	printf("Thread (%p) attached.\n", monoThread);
+
+	//normally, some threaded stuff would happen here.
+	
+	printf("Detaching thread (%p)\n", monoThread);
+	mono_thread_detach(monoThread);
+	printf("Thread (%p) detached.\n", monoThread);
+}
+
+int main(int argc, char *argv[]) {
+	
+	mono_set_defaults(0, mono_parse_default_optimizations(NULL));
+	MonoDomain *monoDomain = mono_jit_init("racy");
+	
+	while(TRUE) {
+		pthread_t threads[CHUNK_THREADCOUNT];
+		int i;
+		
+		for(i = 0; i < CHUNK_THREADCOUNT; i++)
+			pthread_create(threads + i, NULL, thread_function, monoDomain);
+
+		for(i = 0; i < CHUNK_THREADCOUNT; i++)
+			pthread_join(threads[i], NULL);
+	}
+	
+	return(0);
+}
+
+Actual Results:
+Program spews logging output interspersed with large number of warnings that look like this:
+
+** (process:8433): WARNING **: _wapi_handle_unref: Attempting to unref unused handle 0x480
+
+Expected Results:
+Program should spew logging output until killed.
+
+How often does this happen? 
+Run the sample code for long enough, and it will generate warning output. This code will 
+ocasionally cause Mono on OS X to crash or deadlock, but that issue will be filed in another bug.
+
+Additional Information:


More information about the mono-bugs mailing list