Bug 52469 - TcpClient.ConnectAsync hangs for a long time
Summary: TcpClient.ConnectAsync hangs for a long time
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Marek Habersack
Depends on:
Reported: 2017-02-13 10:49 UTC by Emil Müller
Modified: 2017-02-13 14:27 UTC (History)
1 user (show)

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 Developer Community or GitHub 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:

Description Emil Müller 2017-02-13 10:49:21 UTC
I believe this is a bug, but not entirely sure.

In an emulator, after disabling my network connection (Windows control panel), ConnectAsync() will hang for a long time before determining that a connection could not be made.
It will also hang after the network connection has been re-enabled, for an equally long period.

I would like to think that:

1. If no network interface is connected/ready, that TcpClient should immediately be able to determine connection failure
2. If not, should at least be able to quickly make a connection after a network interface has been made ready.
Comment 1 Marek Habersack 2017-02-13 14:27:37 UTC
It doesn't appear to be a bug. The connection has some timeout set and it waits for this period of time until the attempt fails. You can try setting a lower timeout to see if that changes the amount of time it spends waiting for the connection. If the network interface is up in the emulator, the only way to determine that the connection failed is to wait for its timeout - this stems from the client-server nature of TCP/IP.

Another issue might be that the Google Android emulator doesn't notice the Windows network connection goes down and doesn't reflect the state of the emulated network device inside the emulator, thus not letting the application know that the connection is gone. If this is what happens it would be a bug in the Google Android emulator and should be filed with the Android project bug tracker.

I'm going to close this bug since I see no evidence of an error. If, however, you determine that the emulated network interface in the emulator reflects the state of the Windows interface and it's Xamarin.Android that fails to notice the network interface being down, please reopen the bug.