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: 2017-05-03 16:42 UTC (History)
11 users (show)

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


Attachments

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?

Note You need to log in before you can comment on or make changes to this bug.