Bug 49161 - TCPClient ExclusiveAddressUse = false socket bind error
Summary: TCPClient ExclusiveAddressUse = false socket bind error
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 4.8.0 (C9)
Hardware: Other Linux
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2016-12-06 23:02 UTC by Phil
Modified: 2016-12-09 01:35 UTC (History)
3 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 Phil 2016-12-06 23:02:44 UTC
I have a simple .Net test process that declares a new TcpClient on a local port and then tries to connect to it.  This compiles and runs on Windows but fails to run under Mono 4.6.2 on a Raspberry Pi 3.  The error is:

System.InvalidOperationException: Bind has already been called for this socket
  at System.Net.Sockets.Socket.set_ExclusiveAddressUse (System.Boolean value) [0x00011] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at System.Net.Sockets.TcpClient.set_ExclusiveAddressUse (System.Boolean value) [0x00000] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at Test.Module1.Main () [0x00008] in <73e78983e4964489ba5dd5feb2953471>:0

If I comment out the clientSocket.ExclusiveAddressUse = False line then it will run as expected however I need to set ExclusiveAddressUse = False as multiple sockets connect to this port.  My process is connecting to a server running locally on the same machine.

Test code to replicate this is:

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
static class Module1
{


	public static void Main()
	{
		// Declare client socket and client stream to get data
		TcpClient clientSocket = new TcpClient();

		try {
			// Connect to socket
			clientSocket.ExclusiveAddressUse = false;
			clientSocket.LingerState.LingerTime = 0;
			clientSocket.Connect("127.0.0.1", 30005);
		} catch (Exception ex) {
			Console.WriteLine(ex.ToString);
		}

	}

}

I wan't sure which component to assign this to hence my choice of misc.  Apologies if that is wrong.
Comment 1 Ludovic Henry 2016-12-07 16:08:54 UTC
I can reproduce it, but it is fixed on master. I will track down where it was fixed, to try to backport to 4.8
Comment 2 Ludovic Henry 2016-12-07 19:20:04 UTC
This is fixed in master because we imported TcpClient from referencesource, which is not in 4.8 and before.

The test case to reproduce is the following:

> using System;
> using System.Net.Sockets;
> 
> class Driver
> {
> 	public static void Main ()
> 	{
> 		using (TcpClient client = new TcpClient ()) {
> 			client.ExclusiveAddressUse = false;
> 		}
> 	}
> }
Comment 3 Phil 2016-12-08 08:48:04 UTC
I've just installed 4.9.0 from the nightly build and can confirm that my test process works so this bug can be closed.  I couldn't find 4.8 to install.

Any idea how long it will be before 4.8 or 4.9 are released ?  Or is there a way to patch the current 4.6 version ?
Comment 4 Marek Safar 2016-12-09 01:35:30 UTC
Fixed in master.

We don't have plans to backport it to earlier versions