Bug 230 - Http connection to server with NTLM authentication timeouts very often
Summary: Http connection to server with NTLM authentication timeouts very often
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 1.0
Hardware: All All
: --- major
Target Milestone: ---
Assignee: Gonzalo Paniagua Javier
Depends on:
Reported: 2011-08-08 11:55 UTC by Michal
Modified: 2011-08-22 23:19 UTC (History)
4 users (show)

Tags: NTLM, timeout, HTTPWebRequest, System.Net.Exception
Is this bug a regression?: ---
Last known good build:

Samples demonstrating the problem. (28.73 KB, application/zip)
2011-08-08 11:55 UTC, Michal

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 Michal 2011-08-08 11:55:45 UTC
Created attachment 89 [details]
Samples demonstrating the problem.

Using HttpWebRequest to POST some data to a server with NTLM authentication and waiting for some response from server very often ends with System.Net.WebException: The operation has timed out.

The same problem is also in MonoTouch.

Steps to reproduce:
1. Build and deploy NTLMServer project.
2. Open Android or iOS client (NTLMClient/iOS or NTLMClient/Android). Alternatively you can check the result with Win32 client as well.
3. Modify source code to provide correct url path and credentials:
   Android: Activity1.cs - lines 50 and 54
   iOS: Main.cs - lines 119 and 123
4. Build, deploy and run client app.

Client tries 100 times to send and receive some data to/from server. Check device screen for result. All iterations should end with OK status and without any errors.
Comment 1 Jonathan Pryor 2011-08-08 17:04:29 UTC
The specified bug may be fixed in 1.0.2, to be replaced by a different bug.

What I did (on OSX):

 1. Extract the "Samples demonstrating the problem" NTLMTest.zip.
 2. (cd NTLMServer && xbuild)
 3. Edit NTLMClient/Win32/Program.cs, and change line 19 to:

	var url = @"http://localhost:8080/Default.aspx";

    Specifically, I'm changing the IP address and removing "NTLMTest" from the URL.
    Removing "NTLMTest" is needed so that (5)(a) works.

 4. (cd NTLMClient/Win32 && xbuild)
 5. Open two shells (both in $CWD)
   (a) (cd NTLMServer && xsp)
   (b) (cd NTLMClient/Win32 && mono bin/Debug/NTLMClient.exe)

The Win32 client works successfully. Yay.

 6. Edit NTLMClient/Android/Activity1.cs, and change line 50 as was done in (3) but using an explicit IP address, e.g.

	var url = @"";

 7. Build/install/run the NTLMClient/Android app.

At this point, it receives ~40 messages before it dies, but it dies due to a NulllReferenceException, _not_ a WebException:

I/MonoDroid( 9955): UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
I/MonoDroid( 9955): at Java.Lang.Thread/RunnableImplementor.Run () <0x000c4>
I/MonoDroid( 9955): at Java.Lang.IRunnableAdapter.n_Run (intptr,intptr) <0x00037>
I/MonoDroid( 9955): at (wrapper dynamic-method) object.b56fa1f4-8bcf-45b1-9d80-771daa7615b2 (intptr,intptr) <0x0002b>

This is presumably due to the SetTitleOnMainThread() or WriteLineOnMainThread(), and the crash is probably due to a GC issue; this will need further investigation.
Comment 2 Michal 2011-08-09 08:57:52 UTC
I rebuilded Android app with the latest and greatest Mono for Android 1.0.2 and ended up with the same result "The operation has timed out".

If it hepls, I'm testing it on: Server is running in Win7 64 on a laptop connected to LAN. Also wifi hotspot is connected to the same LAN. Client is running on Nexus S which is connected through wifi.
Comment 3 Jonathan Pryor 2011-08-09 13:19:20 UTC
If I'm lucky, Bug #245 is a simplification of the NullReferenceException issue
mentioned in Comment #1. I'm not sure I'm that lucky, though, given that Bug
#245 doesn't elicit a NullReferenceException...
Comment 4 Jonathan Pryor 2011-08-09 13:21:08 UTC
@Michal: How many loops does it complete for you before you get the WebException?
Comment 5 Michal 2011-08-10 03:50:38 UTC
@Jonathan: It's random. I started app for a few times with these numbers (of successful attempts): 1, 1, 0, 5, 2, 36, 17, 18, 11, 0, 2, 5, 17, 14, 17
Comment 6 Jonathan Pryor 2011-08-22 23:19:21 UTC
This appears to be fixed in 1.0.3.

I'm able to run the test (with the changes mentioned in Comment #1) and complete all 100 tests without error on my N1.