Bug 30434 - Strange http exceptions
Summary: Strange http exceptions
Status: NEEDINFO
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: unspecified
Hardware: PC Windows
: High normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-05-26 08:05 UTC by Grigory (Playtika)
Modified: 2018-02-02 10:55 UTC (History)
12 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 for Bug 30434 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEEDINFO

Description Grigory (Playtika) 2015-05-26 08:05:47 UTC
System.Net.WebException: Error getting response stream (InitRead): ReceiveFailure ---> System.NullReferenceException: Object reference not set to an instance of an object
  at System.Net.WebConnection.InitRead (System.Object state) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  at System.Threading.Tasks.TaskFactory`1[System.IO.Stream].FromAsyncCoreLogic (IAsyncResult iar, System.Func`2 endFunction, System.Action`1 endAction, System.Threading.Tasks.Task`1 promise, Boolean requiresSynchronization) [0x00000] in <filename unknown>:0 

  at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x00000] in <filename unknown>:0 
  at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext () [0x00000] in <filename unknown>:0 
  at SF.Common.Network.HttpService+<ExecuteInternal>d__6.MoveNext () [0x00000] in <filename unknown>:0 



System.Net.WebException: Error getting response stream (ReadDone2): ReceiveFailure ---> System.Exception:    at System.Net.WebConnection.HandleError(WebExceptionStatus st, System.Exception e, System.String where)
   at System.Net.WebConnection.ReadDone(IAsyncResult result)
  at System.Net.WebConnection.HandleError (WebExceptionStatus st, System.Exception e, System.String where) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  at System.Threading.Tasks.TaskFactory`1[System.Net.WebResponse].FromAsyncCoreLogic (IAsyncResult iar, System.Func`2 endFunction, System.Action`1 endAction, System.Threading.Tasks.Task`1 promise, Boolean requiresSynchronization) [0x00000] in <filename unknown>:0 
  at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x00000] in <filename unknown>:0 
  at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext () [0x00000] in <filename unknown>:0 
  at SF.Common.Network.HttpService+<ExecuteInternal>d__6.MoveNext () [0x00000] in <filename unknown>:0 



System.Net.WebException: Error: ConnectFailure (interrupted) ---> System.Net.Sockets.SocketException: interrupted
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0 
  at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  at System.Threading.Tasks.TaskFactory`1[System.IO.Stream].FromAsyncCoreLogic (IAsyncResult iar, System.Func`2 endFunction, System.Action`1 endAction, System.Threading.Tasks.Task`1 promise, Boolean requiresSynchronization) [0x00000] in <filename unknown>:0 
  at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x00000] in <filename unknown>:0 
  at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext () [0x00000] in <filename unknown>:0 
  at SF.Common.Network.HttpService+<ExecuteInternal>d__6.MoveNext () [0x00000] in <filename unknown>:0 

System.Net.WebException: Error: SendFailure (The object was used after being disposed.) ---> System.ObjectDisposedException: The object was used after being disposed.
  at System.Net.WebConnection.BeginWrite (System.Net.HttpWebRequest request, System.Byte[] buffer, Int32 offset, Int32 size, System.AsyncCallback cb, System.Object state) [0x00000] in <filename unknown>:0 
  at System.Net.WebConnectionStream.SetHeadersAsync (System.Net.SimpleAsyncResult result, Boolean setInternalLength) [0x00000] in <filename unknown>:0 
  at System.Net.WebConnectionStream+<SetHeadersAsync>c__AnonStorey0.<>m__0 (System.Net.SimpleAsyncResult r) [0x00000] in <filename unknown>:0 
  at System.Net.SimpleAsyncResult.Run (System.Net.SimpleAsyncFunc func, System.Net.SimpleAsyncCallback callback) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  at System.Threading.Tasks.TaskFactory`1[System.IO.Stream].FromAsyncCoreLogic (IAsyncResult iar, System.Func`2 endFunction, System.Action`1 endAction, System.Threading.Tasks.Task`1 promise, Boolean requiresSynchronization) [0x00000] in <filename unknown>:0 
  at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x00000] in <filename unknown>:0 
  at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext () [0x00000] in <filename unknown>:0 
  at SF.Common.Network.HttpService+<ExecuteInternal>d__6.MoveNext () [0x00000] in <filename unknown>:0
Comment 1 Danish Akhtar 2015-06-30 01:48:07 UTC
Hi Grigory ,

Could you please provide some steps or specific test project ? So that we can try to reproduce this issue at our end.

Thanks
Comment 2 Roman Cervenak 2015-07-20 03:14:31 UTC
I can confirm these errors. Hovever, I can never see them in testing environment, only in logs from production sent by client apps. I suspect the bad connection (3G) to be the reason, so I can understand "interupted" errors, but "The object was used after being disposed" or NullReferenceException doesnt seem legit...

-----------------

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Error: ConnectFailure (interrupted) ---> System.Net.Sockets.SocketException: interrupted
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in :0 
at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x00000] in :0 
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult) [0x00000] in :0 
at System.Net.Http.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult, System.Net.TransportContext& context) [0x00000] in :0 
at System.Net.Http.HttpClientHandler.GetRequestStreamCallback (IAsyncResult ar) [0x00000] in :0 
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0 
at System.Runtime.CompilerServices.TaskAwaiter`1[System.Net.Http.HttpResponseMessage].GetResult () [0x00000] in :0 
...

-----------------

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Error: SendFailure (The object was used after being disposed.) ---> System.ObjectDisposedException: The object was used after being disposed.
at System.Net.WebConnection.BeginWrite (System.Net.HttpWebRequest request, System.Byte[] buffer, Int32 offset, Int32 size, System.AsyncCallback cb, System.Object state) [0x00000] in :0 
at System.Net.WebConnectionStream.SetHeadersAsync (System.Net.SimpleAsyncResult result, Boolean setInternalLength) [0x00000] in :0 
at System.Net.WebConnectionStream+c__AnonStorey0.<>m__0 (System.Net.SimpleAsyncResult r) [0x00000] in :0 
at System.Net.SimpleAsyncResult.Run (System.Net.SimpleAsyncFunc func, System.Net.SimpleAsyncCallback callback) [0x00000] in :0 
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult) [0x00000] in :0 
at System.Net.Http.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult, System.Net.TransportContext& context) [0x00000] in :0 
at System.Net.Http.HttpClientHandler.GetRequestStreamCallback (IAsyncResult ar) [0x00000] in :0 
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0 
at System.Runtime.CompilerServices.TaskAwaiter`1[System.Net.Http.HttpResponseMessage].GetResult () [0x00000] in :0 
...

-----------------

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Error getting response stream (InitRead): ReceiveFailure ---> System.NullReferenceException: Object reference not set to an instance of an object
at System.Net.WebConnection.InitRead (System.Object state) [0x00000] in :0 
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult) [0x00000] in :0 
at System.Net.Http.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult, System.Net.TransportContext& context) [0x00000] in :0 
at System.Net.Http.HttpClientHandler.GetRequestStreamCallback (IAsyncResult ar) [0x00000] in :0 
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0 
at System.Runtime.CompilerServices.TaskAwaiter`1[System.Net.Http.HttpResponseMessage].GetResult () [0x00000] in :0
...
Comment 3 aed 2016-04-09 17:15:42 UTC
I also repro this in production. 

System.Net.WebExceptionError getting response stream (InitRead): ReceiveFailure
System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult)
System.Threading.Tasks.TaskFactory<TResult>.FromAsyncCoreLogic(IAsyncResult iar, Func<_,_> endFunction, Action<_> endAction, Task<_> promise, bool requiresSynchronization)
System.Net.Http.HttpClientHandler.SendAsync()
System.Net.Http.HttpClient.SendAsyncWorker()
System.NullReferenceExceptionObject reference not set to an instance of an object
System.Net.WebConnection.InitRead(object state)
Comment 4 Ray Kelly 2016-04-23 01:46:05 UTC
I also see these crashes and can confirm it only seems to happen on really bad WiFi/Cell connections.  I am able to repro every time on crappy GoGo Inflight Wifi and hotel wifi connections.  You may be able to repro by setting the emulator network to 3G and "poor" connection.  Then just send an HTTPClient request.
Comment 5 Ray Kelly 2016-04-23 01:57:30 UTC
I suspect the bug is in this class

https://github.com/mono/mono/blob/master/mcs/class/System/System.Net/WebConnection.cs

and this function

		internal static void InitRead (object state)
		{
			WebConnection cnc = (WebConnection) state;
			Stream ns = cnc.nstream;

			try {
				int size = cnc.buffer.Length - cnc.position;
				ns.BeginRead (cnc.buffer, cnc.position, size, readDoneDelegate, cnc);
			} catch (Exception e) {
				cnc.HandleError (WebExceptionStatus.ReceiveFailure, e, "InitRead");
			}
		}

****Stream ns = cnc.nstream;***
cnc is null, this line is outside of the try.  

Or cnc is null and the catch does not check for null and blows up in the catch.   

Just a shot in the dark here.
Comment 6 henrik 2017-04-26 11:53:43 UTC
I believe you can reproduce by running the Suave tests from https://github.com/SuaveIO/suave/blob/master/.travis.yml#L9 in a loop.

https://travis-ci.org/SuaveIO/suave/ keeps failing since a long time back for bugs like this.
Comment 7 Todd Diehl 2017-05-03 16:42:51 UTC
Does https://github.com/mono/mono/pull/4693 resolve these issues?
Comment 8 castagna.vin 2018-02-02 10:55:16 UTC
Still got this issue randomly on a GetAsync ...