[Mono-bugs] [Bug 74962][Nor] New - UnregisterChannel doesn't release socket right away (racing condition)

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sun May 15 19:00:20 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by pisanko at gmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=74962

--- shadow/74962	2005-05-15 19:00:20.000000000 -0400
+++ shadow/74962.tmp.4430	2005-05-15 19:00:20.000000000 -0400
@@ -0,0 +1,119 @@
+Bug#: 74962
+Product: Mono: Runtime
+Version: 1.1
+OS: 
+OS Details: Ubuntu Linux 5.04
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: remoting
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: pisanko at gmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: UnregisterChannel doesn't release socket right away (racing condition)
+
+Consider following piece of code:
+
+--- cut here ---
+using System;
+using System.Threading;
+using System.Collections;
+
+using System.Runtime.Remoting;
+
+using System.Runtime.Remoting.Channels;
+
+using System.Runtime.Remoting.Channels.Tcp;
+
+using System.Runtime.Serialization.Formatters;
+
+
+class MainClass
+{
+	protected const string CHANNEL_NAME = "My Channel";
+	
+	public static void Main(string[] args)
+	{
+		for (int index = 0; index < 100; index ++)
+		{
+			RegisterChannel();		
+			UnregisterChannel();
+//			Thread.Sleep(50);
+		}
+	}
+	
+	public static void RegisterChannel()
+	{
+		BinaryServerFormatterSinkProvider binaryServerFormatterSinkProvider = new
+BinaryServerFormatterSinkProvider();
+
+		binaryServerFormatterSinkProvider.TypeFilterLevel = TypeFilterLevel.Full;
+		IDictionary channelProperties = new Hashtable();
+
+		channelProperties["name"] = CHANNEL_NAME;
+
+		channelProperties["port"] = 5678;
+
+		TcpChannel tcpChannel = new TcpChannel(channelProperties, null,
+binaryServerFormatterSinkProvider);
+
+		ChannelServices.RegisterChannel(tcpChannel);
+		Console.WriteLine("Channel registered");
+	}
+	
+	public static void UnregisterChannel()
+	{
+		IChannel channel = ChannelServices.GetChannel(CHANNEL_NAME);
+		ChannelServices.UnregisterChannel(channel);
+		Console.WriteLine("Channel unregistered");
+	}
+}
+--- cut here ---
+
+In most cases it will finish with output like this:
+
+--- cut here ---
+Channel registered
+Channel unregistered
+Channel registered
+Channel unregistered
+Channel registered
+Channel unregistered
+Channel registered
+Channel unregistered
+Channel registered
+Channel unregistered
+Channel registered
+Channel unregistered
+Channel registered
+Channel unregistered
+
+Unhandled Exception: System.Net.Sockets.SocketException: Address already in use
+in [0x0005a] System.Net.Sockets.Socket:Bind (System.Net.EndPoint local_end)
+in [0x0002f] (at
+/build/buildd/mono-1.1.7/mcs/class/System/System.Net.Sockets/TcpListener.cs:213)
+System.Net.Sockets.TcpListener:Start ()
+in [0x00034] (at
+/build/buildd/mono-1.1.7/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Tcp/TcpServerChannel.cs:225)
+System.Runtime.Remoting.Channels.Tcp.TcpServerChannel:StartListening
+(System.Object data)
+in [0x00013] (at
+/build/buildd/mono-1.1.7/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Tcp/TcpChannel.cs:95)
+System.Runtime.Remoting.Channels.Tcp.TcpChannel:StartListening
+(System.Object data)
+in [0x000d4] (at
+/build/buildd/mono-1.1.7/mcs/class/corlib/System.Runtime.Remoting.Channels/ChannelServices.cs:269)
+System.Runtime.Remoting.Channels.ChannelServices:RegisterChannel (IChannel
+chnl)
+in [0x00042] (at /home/alexey/Projects/Bug/Main.cs:32)
+MainClass:RegisterChannel ()
+in [0x00007] (at /home/alexey/Projects/Bug/Main.cs:17) MainClass:Main
+(System.String[] args)
+--- cut here ---
+
+But if you will uncomment Thread.Sleep(50); after UnregisterChannel(); this
+piece of code will work without any problem.


More information about the mono-bugs mailing list