Bug 22717 - Process hangs if there is a socket operation going on
Summary: Process hangs if there is a socket operation going on
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 3.4.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Ludovic Henry
URL:
Depends on:
Blocks:
 
Reported: 2014-09-06 05:59 UTC by Tudor Simionescu
Modified: 2017-02-08 20:22 UTC (History)
2 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 Tudor Simionescu 2014-09-06 05:59:34 UTC
The following program never finishes when run on mono 3.4.0 on Linux (CentOS) (also on mono 3.2.0 on Windows). I have also reproduced it using the csharp REPL. The problem reproduces almost always, though small changes in the program prevent it from happening. If it is not reproducing on your machine, try adding some wait time between creating the thread that tries to accept a connection, and the call to Environment.Exit.

The problem never reproduces if run on the CLR on windows. I also wasn't able to reproduce on mac with mono 3.8.0, but I didn't get a chance to try changing the timing.

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
            Console.WriteLine("Socket created");

            s.Bind(new IPEndPoint(new IPAddress(new byte[] { 127, 0, 0, 1 }), 12345));
            Console.WriteLine("Socket bound");            

            s.Listen(100);
            new Thread(() => s.Accept()).Start();
            //On windows it also reproduces if you replace 
            //the previous line with a call to 
            //s.AcceptAsync(new SocketAsyncEventArgs())

            Console.WriteLine("Exiting...");//the problem may not reproduce without this, it's probably timing dependent
            Environment.Exit(0);
        }
    }
}
Comment 1 Ludovic Henry 2017-02-08 20:22:04 UTC
I cannot reproduce with latest mono: Mono JIT compiler version 4.8.0 (mono-4.8.0-branch/6100225 Thu Jan 12 11:37:51 EST 2017)

Please reopen the bug if you can still witness it.