Bug 13920 - Spawning processes on linux cause deadlock
Summary: Spawning processes on linux cause deadlock
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-08-12 10:41 UTC by Rodrigo Kumpera
Modified: 2014-12-01 04:24 UTC (History)
7 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 FIXED

Description Rodrigo Kumpera 2013-08-12 10:41:58 UTC
Testcase:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;
using System.IO;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Queue<Thread> threads = new Queue<Thread>();
            Random random = new Random();
            for (int threadNum = 0; threadNum < 10; ++threadNum)
            {
                Thread thread = new Thread(new ParameterizedThreadStart(delegate(object o)
                    {
                        for (int processNum = 0; processNum < 100; ++processNum)
                        {
                            string processName = o + "-" + processNum;
                            using (Process p = new Process())
                            {
                                p.StartInfo.FileName = "/bin/sleep";
                                p.StartInfo.Arguments = ((float)(random.NextDouble() * 2)).ToString();
                                Console.Out.WriteLine("Starting " + processName);
                                if (p.Start())
                                {
                                    Console.Out.WriteLine("Started " + processName);

                                    List<string> data = new List<string>();
                                    for (int i = 0; i < 100000; ++i)
                                        data.Add("asdfasdfadfasdfasdfasdfasdfasf" + i);

                                    p.WaitForExit();
                                    Console.Out.WriteLine("Finished " + processName);
                                }
                                else
                                    throw new Exception();
                            }
                        }
                    }));

                thread.Start(threadNum);
                threads.Enqueue(thread);
            }

            Console.Out.WriteLine("Waiting for threads");
            while (threads.Count > 0)
                threads.Dequeue().Join();

            Console.Out.WriteLine("Done");
        }
    }
}
Comment 1 Matthew Gerber 2013-08-12 11:59:55 UTC
Here's what I had to do to produce the deadlock:

1) Compile with "gmcs Program.cs"
2) Run with "mono Program.exe"
3) If the deadlock does not happen in a second or two, hit CTRL+C and restart. It might take a few tries, but I haven't had to try more than 10 times or so.

Here are my specs:

Mono JIT compiler version 3.2.0 (tarball Sat Jul 27 11:48:35 EDT 2013)
Copyright (C) 2002-2012 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

OS:  Xubuntu 12.04
Comment 2 Nikita Tsukanov 2013-08-12 16:33:11 UTC
Hello. I've tried to run your program and can tell that your issue is somehow simular to this one: https://bugzilla.xamarin.com/show_bug.cgi?id=13933

i. e.

1) I can't reproduce your problem with Mono 2.10.8
2) I can't reproduce your problem if I run your program under debugger (MonoDevelop or a dummy one connected manually via --debugger-agent)
3) I can reproduce your problem with Mono 3.0.6, Mono 3.2 and Mono 3.3
Comment 3 Matthew Gerber 2013-08-12 17:22:01 UTC
I, too, have been unable to get the program listed above to lock up using 2.10.8 (compiled from source). However, it locks up regularly using 3.2.0 (as I described above).
Comment 4 Matthew Gerber 2013-08-18 00:31:46 UTC
This appears to have been fixed with the work done to resolve the following bug:

https://bugzilla.xamarin.com/show_bug.cgi?id=13951

Since that commit I haven't been able to reproduce this particular hang. Feel free to mark as resolved and I'll post back if the hang creeps up again.
Comment 5 Zoltan Varga 2014-12-01 04:24:41 UTC
-> FIXED.