Bug 349680

Summary: Unreleased and Un-closed Mutex keeps app from exiting.
Product: [Mono] Mono: Runtime Reporter: Jae Stutzman <jaebird>
Component: io-layerAssignee: Dick Porter <dick>
Status: RESOLVED FIXED QA Contact: Mono Bugs <mono-bugs>
Severity: Normal    
Priority: P5 - None CC: forgotten_vxPDddArjq
Version: 1.2.4   
Target Milestone: ---   
Hardware: i386   
OS: Ubuntu   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Jae Stutzman 2007-12-19 00:46:40 UTC
Description of Problem:

Mutex class acts differently from MS on exit.

Steps to reproduce the problem:
1. Run the app below. It should exit properly
2. Now remove the onlyOne.ReleaseMutex(); line. The app does not completely exit


Actual Results:
Sometimes app hangs on exit and does not return to the shell.

Expected Results:
Exit and return to shell


How often does this happen? 
Mostly every time.

Additional Information:

static void Main() 

{
  // allow only one instance of the process
  Mutex onlyOne = new Mutex(true, Process.GetCurrentProcess().ProcessName);

  if (onlyOne.WaitOne(0, false)) {
    try {

      new Program();
    }
    finally {
      onlyOne.ReleaseMutex();
      onlyOne.Close();
      onlyOne = null;
    }
  }
}

Sometimes, depending on what is in the Program() if the "onlyOne = null" is not present the app does not exit either.
Comment 1 Forgotten User vxPDddArjq 2008-01-09 19:39:06 UTC
-> runtime.

This is most likely caused by  _wapi_thread_set_termination_details
acquiring the shared handles lock, then calling _wapi_thread_abadon_mutexes,
whose documentation states that the lock should not be held by the caller.
Comment 2 Dick Porter 2008-01-16 15:45:13 UTC
Fixed in svn r93046.  The analysis was mostly correct, but _wapi_handle_unref() called from _wapi_thread_disown_mutex() could also try to obtain the shared lock.