Bug 4599 - Regression in network code in Mono 2.11
Summary: Regression in network code in Mono 2.11
Alias: None
Product: Runtime
Classification: Mono
Component: io-layer ()
Version: unspecified
Hardware: PC All
: High major
Target Milestone: ---
Assignee: Gonzalo Paniagua Javier
Depends on:
Reported: 2012-04-23 13:49 UTC by Bojan Rajkovic [MSFT]
Modified: 2012-04-24 04:56 UTC (History)
3 users (show)

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

Sample code to reproduce. (731 bytes, application/octet-stream)
2012-04-23 13:49 UTC, Bojan Rajkovic [MSFT]

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:

Description Bojan Rajkovic [MSFT] 2012-04-23 13:49:20 UTC
Created attachment 1727 [details]
Sample code to reproduce.

Mono 2.11 seems to have introduced a regression in the network code somewhere. The attached code sample works correctly on Mono 2.10.9. Also attached is the output of kill -QUIT on the PID of the stuck process. 

The bug seems to only affect WebRequest requests that call GetRequestStream; using WebClient for a DownloadString operation to HTTPS works, and using WebClient for an UploadString operation to HTTPS works.
Comment 1 Bojan Rajkovic [MSFT] 2012-04-23 13:51:07 UTC
The output of kill -QUIT on the offending process is below. It seems to be trying to finish the handshake negotiation, but it never completes. The output is *not* cut off—the last line printed is "Threadpool monitor," and then no more output is given.

bojanrajkovic@Bojans-MacBook-Pro ~/Code $ mono RegressionRepro2.exe 
Sending POST to https://google.com
Full thread dump:

"<threadpool thread>"
"Threadpool worker"  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Threading.Monitor.try_enter_with_atomic_var (object,int,bool&) <0xffffffff>
  at System.Threading.Monitor.TryEnter (object,int,bool&) <0x0003b>
  at System.Threading.Monitor.Enter (object,bool&) <0x00017>
  at (wrapper unknown) System.Threading.Monitor.FastMonitorEnterV4 (object,bool&) <0xffffffff>
  at System.Net.HttpWebRequest.GetServicePoint () <0x0002f>
  at System.Net.HttpWebRequest.get_ServicePoint () <0x00013>
  at (wrapper remoting-invoke-with-check) System.Net.HttpWebRequest.get_ServicePoint () <0xffffffff>
  at System.Net.ServicePointManager/ChainValidationHelper.ValidateChain (Mono.Security.X509.X509CertificateCollection) <0x0056b>
  at Mono.Security.Protocol.Tls.SslClientStream.OnRemoteCertificateValidation2 (Mono.Security.X509.X509CertificateCollection) <0x0001c>
  at Mono.Security.Protocol.Tls.SslStreamBase.RaiseRemoteCertificateValidation2 (Mono.Security.X509.X509CertificateCollection) <0x00019>
  at Mono.Security.Protocol.Tls.SslClientStream.RaiseServerCertificateValidation2 (Mono.Security.X509.X509CertificateCollection) <0x00013>
  at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection) <0x000a9>
  at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () <0x000cf>
  at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () <0x0004d>
  at (wrapper remoting-invoke-with-check) Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () <0xffffffff>
  at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream) <0x00087>
  at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (System.IAsyncResult) <0x0023b>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <0xffffffff>

"IO Threadpool worker"
"Threadpool worker"  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Threading.WaitHandle.WaitOne_internal (System.Threading.WaitHandle,intptr,int,bool) <0xffffffff>
  at System.Threading.WaitHandle.WaitOne () <0x0005f>
  at Mono.Security.Protocol.Tls.RecordProtocol.EndReceiveRecord (System.IAsyncResult) <0x00073>
  at Mono.Security.Protocol.Tls.RecordProtocol.ReceiveRecord (System.IO.Stream) <0x00027>
  at Mono.Security.Protocol.Tls.SslClientStream.SafeReceiveRecord (System.IO.Stream) <0x0001b>
  at Mono.Security.Protocol.Tls.SslClientStream.OnNegotiateHandshakeCallback (System.IAsyncResult) <0x00037>
  at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (System.IAsyncResult) <0x0006b>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <0xffffffff>

"<unnamed thread>"  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Threading.WaitHandle.WaitOne_internal (System.Threading.WaitHandle,intptr,int,bool) <0xffffffff>
  at System.Threading.WaitHandle.WaitOne () <0x0005f>
  at Mono.Security.Protocol.Tls.SslStreamBase.EndNegotiateHandshake (Mono.Security.Protocol.Tls.SslStreamBase/InternalAsyncResult) <0x0003b>
  at Mono.Security.Protocol.Tls.SslStreamBase.NegotiateHandshake () <0x00087>
  at Mono.Security.Protocol.Tls.SslStreamBase.Write (byte[],int,int) <0x0008b>
  at System.Net.WebConnection.Write (System.Net.HttpWebRequest,byte[],int,int,string&) <0x000ea>
  at System.Net.WebConnectionStream.WriteHeaders () <0x00057>
  at System.Net.WebConnectionStream.SetHeaders (byte[]) <0x0010b>
  at (wrapper remoting-invoke-with-check) System.Net.WebConnectionStream.SetHeaders (byte[]) <0xffffffff>
  at System.Net.HttpWebRequest.SendRequestHeaders (bool) <0x002b7>
  at (wrapper remoting-invoke-with-check) System.Net.HttpWebRequest.SendRequestHeaders (bool) <0xffffffff>
  at System.Net.WebConnectionStream.WriteRequest () <0x001b3>
  at (wrapper remoting-invoke-with-check) System.Net.WebConnectionStream.WriteRequest () <0xffffffff>
  at System.Net.HttpWebRequest.CheckIfForceWrite () <0x000fb>
  at System.Net.HttpWebRequest.BeginGetResponse (System.AsyncCallback,object) <0x000af>
  at System.Net.HttpWebRequest.GetResponse () <0x00017>
  at RegressionRepro.Main (string[]) <0x00184>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>

"Threadpool monitor"
Comment 2 Miguel de Icaza [MSFT] 2012-04-23 22:46:54 UTC
Gonzalo, would you mind checking this one out?
Comment 3 Gonzalo Paniagua Javier 2012-04-24 04:30:57 UTC
Fails on linux. Also fails on (works with 2.10.5).
Comment 4 Gonzalo Paniagua Javier 2012-04-24 04:56:57 UTC
Fixed in master/9007f5e and mono-2-10/bf3a705.

No idea what triggered the problem, but it looks like the validation now happens in a different thread.