Bug 38574 - Runtime crashes when calling Process.GetCurrentProcess().WaitForExit();
Summary: Runtime crashes when calling Process.GetCurrentProcess().WaitForExit();
Status: RESOLVED ANSWERED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-02-09 13:34 UTC by Tobias Kolb
Modified: 2017-11-04 16:49 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Tobias Kolb 2016-02-09 13:34:53 UTC
Runtime crashes when Calling Process.GetCurrentProcess().WaitForExit();

You can do this on the csharp interactive shell or create a simple console application with just a main() method:

static void Main(string[] args)
        {

            // startup wcf self hosted services here
            Console.Out.WriteLine("REST/JSON Services are running...");
            
            // wait forever
            Process.GetCurrentProcess().WaitForExit();
        }

When running the application it will crash with the following output:


REST/JSON Services are running...
* Assertion at processes.c:2734, condition `mp' not met

Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Diagnostics.Process.WaitForExit_internal (System.Diagnostics.Process,intptr,int) <0xffffffff>
  at System.Diagnostics.Process.WaitForExit (int) <0x0022b>
  at System.Diagnostics.Process.WaitForExit () <0x00017>
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.WaitForExit () <0xffffffff>
  at ConsoleApplication1.Program.Main (string[]) <0x0003f>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:


Debug info from gdb:

[New LWP 1196]
[New LWP 1195]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
0x76ef5ee8 in __libc_waitpid (pid=1197, stat_loc=0x7e989ac4, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40
40      ../sysdeps/unix/sysv/linux/waitpid.c: Datei oder Verzeichnis nicht gefunden.
  Id   Target Id         Frame
  3    Thread 0x763ff430 (LWP 1195) "mono" 0x76ef17a4 in __pthread_cond_wait (cond=0x235420, mutex=0x235408) at pthread_cond_wait.c:187
  2    Thread 0x76a6b430 (LWP 1196) "Finalizer" 0x76ef3a40 in do_futex_wait (isem=isem@entry=0x22a58c) at ../nptl/sysdeps/unix/sysv/linux/sem_wait.c:48
* 1    Thread 0x76fe8000 (LWP 1194) "mono" 0x76ef5ee8 in __libc_waitpid (pid=1197, stat_loc=0x7e989ac4, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40

Thread 3 (Thread 0x763ff430 (LWP 1195)):
#0  0x76ef17a4 in __pthread_cond_wait (cond=0x235420, mutex=0x235408) at pthread_cond_wait.c:187
#1  0x001468a8 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 2 (Thread 0x76a6b430 (LWP 1196)):
#0  0x76ef3a40 in do_futex_wait (isem=isem@entry=0x22a58c) at ../nptl/sysdeps/unix/sysv/linux/sem_wait.c:48
#1  0x76ef3af4 in __new_sem_wait (sem=0x22a58c) at ../nptl/sysdeps/unix/sysv/linux/sem_wait.c:69
#2  0x0015f164 in mono_sem_wait ()
#3  0x0010d90c in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 1 (Thread 0x76fe8000 (LWP 1194)):
#0  0x76ef5ee8 in __libc_waitpid (pid=1197, stat_loc=0x7e989ac4, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40
#1  0x0007a328 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================


Background:
I have a simple console application that uses Process.GetCurrentProcess().WaitForExit() in it's main() method to keep a process alive for infinite time. I need this because I set up a self hosted wfc service that otherwise would be closed when the main method returns. 

I'm using Mono on a Raspberry Pi 2 with Raspbian Jessie:
 mono --version
Mono JIT compiler version 4.2.2 (Stable 4.2.2.30/996df3c Fri Jan 22 00:48:14 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       normal
        Notifications: epoll
        Architecture:  armel,vfp+hard
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen
Comment 1 Ludovic Henry 2016-02-16 13:24:13 UTC
Hi Tobias,

This issue is fixed with https://github.com/mono/mono/pull/2610 which is in the process of being merged into master.

For a simple workaround, maybe you could try `Console.ReadLine()` which will stop the Main method to return, until you press a key. If it's not possible, you can simply use `while (true) Thread.Sleep (Int32.MaxValue);`

Thank you for the report,
Ludovic
Comment 2 chevycam 2016-03-24 00:55:49 UTC
I am  still experiencing this issue in 

Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 16 13:19:08 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            sgen

with the following showing up:

Assertion at processes.c:2734, condition `mp' not met

Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Diagnostics.Process.WaitForExit_internal (System.Diagnostics.Process,intptr,int) <0xffffffff>
  at System.Diagnostics.Process.WaitForExit (int) <0x0021b>
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.WaitForExit (int) <0xffffffff>


When is this fix going to be merged into the master?  Do I need to pull from the beta repositories to get this fix?
Comment 3 y.skindersky 2017-11-04 16:49:38 UTC
It seems Process.GetCurrentProcess().WaitForExit(); returns immediately on Ubuntu. Could anybody comment this?