Bug 26514 - System.Diagnostics.Process unstable in 3.12.0
Summary: System.Diagnostics.Process unstable in 3.12.0
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 3.12.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-01-28 14:47 UTC by David Lein
Modified: 2017-01-05 13:31 UTC (History)
5 users (show)

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


Attachments

Description David Lein 2015-01-28 14:47:32 UTC
Run the following code:

        public static void Main(string[] args)
        {
            var procs = Process.GetProcesses();
            foreach (var proc in procs)
            {
                if (proc.HasExited)
                    Console.WriteLine(string.Format("{0} has exited.", proc.ProcessName));
            }
        }

The first major issue is that Process.GetProcesses() throws dozens of ArgumentExceptions internally. (Can't find process with ID 0)
It's not clear if the returned array is usable or corrupt but attempting to access proc.HasExited aborts with the following error:

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

Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Diagnostics.Process.ExitCode_internal (intptr) <IL 0x00021, 0xffffffff>
  at System.Diagnostics.Process.get_HasExited () [0x00020] in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.0/mcs/class/System/System.Diagnostics/Process.cs:195
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.get_HasExited () <IL 0x00038, 0xffffffff>
  at TestProcess.MainClass.Main (string[]) [0x00017] in /Users/david/Projects/TestProcess/TestProcess/Program.cs:23
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

	0   mono                                0x000bae66 mono_handle_native_sigsegv + 342
	1   mono                                0x0010e2aa sigabrt_signal_handler + 122
	2   libsystem_platform.dylib            0x9b806deb _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   libsystem_c.dylib                   0x9971d29c abort + 155
	5   mono                                0x0025c6b1 monoeg_log_default_handler + 129
	6   mono                                0x0025c7ab monoeg_assertion_message + 107
	7   mono                                0x00239a1e process_wait + 782
	8   mono                                0x0023b8c7 GetExitCodeProcess + 167
	9   mono                                0x0019f348 ves_icall_System_Diagnostics_Process_ExitCode_internal + 24
	10  ???                                 0x007b94b4 0x0 + 8098996
	11  ???                                 0x007b940c 0x0 + 8098828
	12  ???                                 0x007b9324 0x0 + 8098596
	13  ???                                 0x007b3128 0x0 + 8073512
	14  ???                                 0x007b3352 0x0 + 8074066
	15  mono                                0x0001064f mono_jit_runtime_invoke + 751
	16  mono                                0x001cf7ff mono_runtime_invoke + 127
	17  mono                                0x001d5641 mono_runtime_exec_main + 401
	18  mono                                0x001d53ea mono_runtime_run_main + 682
	19  mono                                0x00085d8d mono_jit_exec + 93
	20  mono                                0x00088060 mono_main + 7904
	21  mono                                0x00002f60 main + 768
	22  mono                                0x00002c55 start + 53
	23  ???                                 0x00000004 0x0 + 4

Debug info from gdb:

(lldb) command source -s 0 '/tmp/mono-gdb-commands.4y1ESs'
Executing commands in '/private/tmp/mono-gdb-commands.4y1ESs'.
(lldb) process attach --pid 5878
Process 5878 stopped
Executable module set to "/Library/Frameworks/Mono.framework/Versions/3.12.0/bin/mono".
Architecture set to: i386-apple-macosx.
(lldb) thread list
Process 5878 stopped
* thread #1: tid = 0x2a43f, 0x930abfed libsystem_kernel.dylib`__wait4 + 5, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  thread #2: tid = 0x2a44c, 0x930a6fb6 libsystem_kernel.dylib`semaphore_wait_trap + 10
  thread #3: tid = 0x2a44d, 0x930ac992 libsystem_kernel.dylib`kevent64 + 10, queue = 'com.apple.libdispatch-manager'
  thread #4: tid = 0x2a44e, 0x930ac046 libsystem_kernel.dylib`__workq_kernreturn + 10
  thread #5: tid = 0x2a44f, 0x930ac046 libsystem_kernel.dylib`__workq_kernreturn + 10
  thread #6: tid = 0x2a450, 0x930aba26 libsystem_kernel.dylib`__recvfrom + 10
(lldb) thread backtrace all
* thread #1: tid = 0x2a43f, 0x930abfed libsystem_kernel.dylib`__wait4 + 5, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x930abfed libsystem_kernel.dylib`__wait4 + 5
    frame #1: 0x9973bec5 libsystem_c.dylib`waitpid$UNIX2003 + 48
    frame #2: 0x000baf2d mono`mono_handle_native_sigsegv(signal=6, ctx=0xbfffe5bc) + 541 at mini-exceptions.c:2323
    frame #3: 0x0010e2aa mono`sigabrt_signal_handler(_dummy=<unavailable>, context=<unavailable>, _info=<unavailable>) + 122 at mini-posix.c:207
    frame #4: 0x9b806deb libsystem_platform.dylib`_sigtramp + 43
    frame #5: 0x930ab953 libsystem_kernel.dylib`__pthread_kill + 11
    frame #6: 0x9971d29c libsystem_c.dylib`abort + 155
    frame #7: 0x0025c6b1 mono`monoeg_log_default_handler(log_domain=<unavailable>, log_level=<unavailable>, message=<unavailable>, unused_data=<unavailable>) + 129 at goutput.c:232
    frame #8: 0x0025c7ab mono`monoeg_assertion_message [inlined] monoeg_g_logv(log_level=<unavailable>, format=<unavailable>) + 85 at goutput.c:113
    frame #9: 0x0025c756 mono`monoeg_assertion_message(format=<unavailable>) + 22 at goutput.c:133
    frame #10: 0x00239a1e mono`process_wait(handle=<unavailable>, timeout=<unavailable>, alertable=<unavailable>) + 782 at processes.c:2595
    frame #11: 0x0023b8c7 mono`GetExitCodeProcess(process=0x00000101, code=<unavailable>) + 167 at processes.c:1250
    frame #12: 0x0019f348 mono`ves_icall_System_Diagnostics_Process_ExitCode_internal(process=0x00000101) + 24 at process.c:776
    frame #13: 0x007b94b4
    frame #14: 0x007b940c
    frame #15: 0x007b9324
    frame #16: 0x007b3128
    frame #17: 0x007b3352
    frame #18: 0x0001064f mono`mono_jit_runtime_invoke(method=<unavailable>, obj=<unavailable>, params=<unavailable>, exc=<unavailable>) + 751 at mini.c:6735
    frame #19: 0x001cf7ff mono`mono_runtime_invoke(method=0x7c1eeec4, obj=0x00000000, params=<unavailable>, exc=<unavailable>) + 127 at object.c:2842
    frame #20: 0x001d5641 mono`mono_runtime_exec_main(method=0x7c1eeec4, args=<unavailable>, exc=0x00000000) + 401 at object.c:4099
    frame #21: 0x001d53ea mono`mono_runtime_run_main(method=0x00800710, argc=<unavailable>, argv=<unavailable>, exc=<unavailable>) + 682 at object.c:3725
    frame #22: 0x00085d8d mono`mono_jit_exec(domain=0x7aa17470, assembly=0x7971a8c0, argc=<unavailable>, argv=<unavailable>) + 93 at driver.c:1006
    frame #23: 0x00088060 mono`mono_main [inlined] main_thread_handler + 7904 at driver.c:1065
    frame #24: 0x00088022 mono`mono_main(argc=<unavailable>, argv=<unavailable>) + 7842 at driver.c:2060
    frame #25: 0x00002f60 mono`main [inlined] mono_main_with_options(argc=<unavailable>, argv=<unavailable>) + 768 at main.c:94
    frame #26: 0x00002c7d mono`main(argc=<unavailable>, argv=<unavailable>) + 29 at main.c:125
    frame #27: 0x00002c55 mono`start + 53

  thread #2: tid = 0x2a44c, 0x930a6fb6 libsystem_kernel.dylib`semaphore_wait_trap + 10
    frame #0: 0x930a6fb6 libsystem_kernel.dylib`semaphore_wait_trap + 10
    frame #1: 0x00251c3a mono`mono_sem_wait(sem=0x003574b8, alertable=1) + 26 at mono-semaphore.c:103
    frame #2: 0x001ccb9e mono`finalizer_thread(unused=0x00000000) + 142 at gc.c:1077
    frame #3: 0x001aaf81 mono`start_wrapper [inlined] start_wrapper_internal + 484 at threads.c:663
    frame #4: 0x001aad9d mono`start_wrapper(data=<unavailable>) + 29 at threads.c:710
    frame #5: 0x00257160 mono`inner_start_thread(arg=<unavailable>) + 240 at mono-threads-posix.c:88
    frame #6: 0x997545fb libsystem_pthread.dylib`_pthread_body + 144
    frame #7: 0x99754485 libsystem_pthread.dylib`_pthread_start + 130
    frame #8: 0x99759cf2 libsystem_pthread.dylib`thread_start + 34

  thread #3: tid = 0x2a44d, 0x930ac992 libsystem_kernel.dylib`kevent64 + 10, queue = 'com.apple.libdispatch-manager'
    frame #0: 0x930ac992 libsystem_kernel.dylib`kevent64 + 10
    frame #1: 0x91c4e899 libdispatch.dylib`_dispatch_mgr_invoke + 238
    frame #2: 0x91c4e532 libdispatch.dylib`_dispatch_mgr_thread + 52

  thread #4: tid = 0x2a44e, 0x930ac046 libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x930ac046 libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x99755dcf libsystem_pthread.dylib`_pthread_wqthread + 372
    frame #2: 0x99759cce libsystem_pthread.dylib`start_wqthread + 30

  thread #5: tid = 0x2a44f, 0x930ac046 libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #0: 0x930ac046 libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x99755dcf libsystem_pthread.dylib`_pthread_wqthread + 372
    frame #2: 0x99759cce libsystem_pthread.dylib`start_wqthread + 30

  thread #6: tid = 0x2a450, 0x930aba26 libsystem_kernel.dylib`__recvfrom + 10
    frame #0: 0x930aba26 libsystem_kernel.dylib`__recvfrom + 10
    frame #1: 0x9973c0c9 libsystem_c.dylib`recv$UNIX2003 + 54
    frame #2: 0x000f3088 mono`socket_transport_recv(buf=<unavailable>, len=<unavailable>) + 168 at debugger-agent.c:1139
    frame #3: 0x000e50d7 mono`debugger_thread [inlined] transport_recv(len=<unavailable>) + 31 at debugger-agent.c:1565
    frame #4: 0x000e50b8 mono`debugger_thread(arg=0x00000000) + 1560 at debugger-agent.c:9600
    frame #5: 0x00257160 mono`inner_start_thread(arg=<unavailable>) + 240 at mono-threads-posix.c:88
    frame #6: 0x997545fb libsystem_pthread.dylib`_pthread_body + 144
    frame #7: 0x99754485 libsystem_pthread.dylib`_pthread_start + 130
    frame #8: 0x99759cf2 libsystem_pthread.dylib`thread_start + 34
(lldb) detach
(lldb) quit
Process 5878 detached
(lldb) 
error: No auto repeat.
(lldb)
Comment 1 David Lein 2015-01-28 14:50:10 UTC
This defect did not occur in 3.10.0
Comment 2 Gwendal 2015-01-31 04:51:48 UTC
I have a similar issue when trying to run sonarr (former "nzbdrone") with mono 3.12.0. Here is what happens (and didn't happen with previous mono versions) :

------------------------------
[xxx@yyy nzbdrone]# mono --debug NzbDrone.exe
-bash: mono: command not found
[root@kahn nzbdrone]# /opt/mono/bin/mono --debug NzbDrone.exe
[Info] Bootstrap: Starting NzbDrone - /opt/nzbdrone/NzbDrone.exe - Version 2.0.0.2579 
* Assertion at processes.c:2595, condition `mp' not met

Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Diagnostics.Process.ExitCode_internal (intptr) <IL 0x0000d, 0xffffffff>
  at System.Diagnostics.Process.get_HasExited () [0x00020] in /home/abuild/rpmbuild/BUILD/mono-3.12.0/mcs/class/System/System.Diagnostics/Process.cs:195
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.get_HasExited () <IL 0x00038, 0xffffffff>
  at NzbDrone.Common.Processes.ProcessProvider.ConvertToProcessInfo (System.Diagnostics.Process) [0x00044] in m:\BuildAgent\work\328d72309b633a8\src\NzbDrone.Common\Processes\ProcessProvider.cs:264
  at NzbDrone.Common.Processes.ProcessProvider.GetCurrentProcess () [0x00000] in m:\BuildAgent\work\328d72309b633a8\src\NzbDrone.Common\Processes\ProcessProvider.cs:46
  at NzbDrone.Common.Processes.PidFileProvider.Write () [0x0001e] in m:\BuildAgent\work\328d72309b633a8\src\NzbDrone.Common\Processes\PidFileProvider.cs:36
  at NzbDrone.Host.Bootstrap.Start (NzbDrone.Common.EnvironmentInfo.StartupContext,NzbDrone.Host.IUserAlert,System.Action`1<NzbDrone.Common.Composition.IContainer>) [0x0005a] in m:\BuildAgent\work\328d72309b633a8\src\NzbDrone.Host\Bootstrap.cs:34
  at NzbDrone.Console.ConsoleApp.Main (string[]) [0x0000f] in m:\BuildAgent\work\328d72309b633a8\src\NzbDrone.Console\ConsoleApp.cs:20
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

	/opt/mono/bin/mono() [0x4f4178]
	/lib64/libpthread.so.0(+0xf130) [0x7fc1e0b5b130]
	/lib64/libc.so.6(gsignal+0x39) [0x7fc1e05aa5c9]
	/lib64/libc.so.6(abort+0x148) [0x7fc1e05abcd8]
	/opt/mono/bin/mono() [0x6741c9]
	/opt/mono/bin/mono() [0x6743cf]
	/opt/mono/bin/mono() [0x674516]
	/opt/mono/bin/mono() [0x6532b5]
	/opt/mono/bin/mono() [0x6547c3]
	/opt/mono/bin/mono() [0x5cd8ce]
	[0x41051c25]

Debug info from gdb:


=================================================================
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.
=================================================================

Aborted
------------------------------
Comment 3 henrik 2015-02-12 11:53:27 UTC
Might it be this commit?

https://github.com/mono/mono/commit/97866fc14501588f8773d02fe1596fa2e7cc9a70
Comment 4 henrik 2015-02-12 12:02:57 UTC
Duplicate to https://bugzilla.xamarin.com/show_bug.cgi?id=25720?
Comment 5 henrik 2015-02-12 12:03:09 UTC
Trying HEAD.
Comment 6 Zoltan Varga 2015-02-12 12:08:35 UTC
This is a dup of #25720.
Comment 7 Alexander Köplinger [MSFT] 2017-01-05 13:31:18 UTC
#25720 was fixed and in the meantime we migrated to using the Process code from referencesource so this should be fixed as well. Thanks.

Note You need to log in before you can comment on or make changes to this bug.