Bug 26044 - Repeated use of HttpClient causes exception
Summary: Repeated use of HttpClient causes exception
Status: RESOLVED ANSWERED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Net.Http ()
Version: unspecified
Hardware: Other Other
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-01-14 19:45 UTC by tmrog
Modified: 2015-01-22 05:34 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Xamarin version information (1.34 KB, text/plain)
2015-01-14 19:45 UTC, tmrog
Details


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 ANSWERED

Description tmrog 2015-01-14 19:45:04 UTC
Created attachment 9358 [details]
Xamarin version information

When using HttpClient to make web requests on an iPhone I intermittently get the exception below.

A few notes:
1. I am reusing HttpClient object but never run concurrent requests on the same HttpClient.
2. I have a pool of HttpClients that usually ranges from 2-3 depending on usage.
3. I patterned my code based on a blog entry by Henrik on how to use HttpClient using ContinueWith.
4. I create a new task for each request prior to making request.
5. If I repeat the request immediately with the same HttpClient, it works.
6. It seems to always fail on the PostAsync, not the later

Steps to reproduce:  Repeated PostAsync requests on the same HttpClient.

The exception is this:

*****MakeWebReqeust NullReferenceException for url = chat/receive: message = 'Object reference not set to an instance of an object' elapsed time = 505
stack trace =   at System.Net.Http.HttpClientHandler.CreateResponseMessage (System.Net.HttpWebResponse wr, System.Net.Http.HttpRequestMessage requestMessage, CancellationToken cancellationToken) [0x00000] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.47/src/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs:290 
  at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x0041f] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.47/src/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs:355 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Net.Http.HttpResponseMessage].GetResult () [0x00000] in <filename unknown>:0 
  at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext () [0x000a9] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.47/src/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClient.cs:273
Comment 1 Marek Safar 2015-01-15 03:48:39 UTC

*** This bug has been marked as a duplicate of bug 22724 ***
Comment 2 tmrog 2015-01-15 09:48:15 UTC
@Marek Safar - I am familiar with the bug you reference but I don't believe this is a duplicate of that.  I am NOT running concurrent requests.  I am reusing the same HTTPClient object but I never run concurrent requests.
Comment 3 Marek Safar 2015-01-20 11:29:07 UTC
#22724 does not need to involve concurrent request. I believe the issues was address. If you have repro which does still exhibits the problem, please reopen the bug report.
Comment 4 tmrog 2015-01-20 12:17:51 UTC
@marek Safar - #22724 specifically refers to android.  Does the fix apply to iOS as well?
Comment 5 Marek Safar 2015-01-20 15:48:06 UTC
yes, the code is exactly same
Comment 6 tmrog 2015-01-20 17:10:50 UTC
@Marek Safar - thanks.  So, how do I get the fix?  Is this on the alpha, beta, or stable channels?
Comment 7 Marek Safar 2015-01-22 05:34:39 UTC
Yes, the fix should be included in latest Xamarin.iOS alpha