[Mono-bugs] [Bug 642224] New: TcpListener keeps blocking after aborting its owner thread

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Sep 28 04:04:08 EDT 2010


https://bugzilla.novell.com/show_bug.cgi?id=642224

https://bugzilla.novell.com/show_bug.cgi?id=642224#c0


           Summary: TcpListener keeps blocking after aborting its owner
                    thread
    Classification: Mono
           Product: Mono: Class Libraries
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: aenomoto at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


The following code on .NET exits normally (i.e. aborts the thread and dies
without problem), but on Mono does not exit while both main thread (that called
Thread.Abort) and the aborted thread reach their end points (i.e. they print
"Aborted" and "done." for each).

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

public class Test
{
    public static void Main ()
    {
        var t = new Thread (new ThreadStart (StartListener));
        t.Start ();
        Thread.Sleep (5000);
        Console.WriteLine ("Aborting...");
        t.Abort ();
        Console.WriteLine ("Aborted");
    }

    static void StartListener ()
    {
#if true
        var l = new TcpListener (9090);
        l.Start ();
        try {
            while (true) {
                var cli = l.EndAcceptTcpClient (l.BeginAcceptTcpClient (null,
null));
                cli.Close ();
            }
        } finally {
            Console.WriteLine ("done.");
        }
#else
        var d = new Action (DoWork);
        try {
            d.EndInvoke (d.BeginInvoke (null, null));
        } finally {
            Console.WriteLine ("done.");
        }
#endif
    }

    static void DoWork ()
    {
        Thread.Sleep (10000);
    }
}

--------

Note that for usual thread activities it works fine e.g. toggling #if switch in
the above code works fine (the program exits).

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list