Convert blocking operations in HttpWebRequest and SslClientStream to non-blocking...
authorBassam Tabbara <bassam@symform.com>
Fri, 6 Dec 2013 00:21:15 +0000 (16:21 -0800)
committerBassam Tabbara <bassam@symform.com>
Fri, 6 Dec 2013 17:32:22 +0000 (09:32 -0800)
commit90f9595967f656498e2143b2a04705dd18da6913
treef225be451156c32b291dcf5c844b8472f43e4f45
parentb535b6a55336ba9c03d4e8967c7fd15ab1a5d9cc
Convert blocking operations in HttpWebRequest and SslClientStream to non-blocking operations. This fixes #15451.

More details:
  * HttpWebRequest now writes the HTTP request headers asynchronously. This will avoid blocking a thread pool thread until the headers are written.
  * SslClientStream was doing the TLS negotiations in a blocking manner. Converted the negotiation method to an async state machine where all operations are done asynchronously.
  * The test case identified in #15451 now completes quickly with less than 15 threads created, vs. 100s of threads used before this fix.

Future work if needed:
  * I did not convert SslServerStream but the same pattern could be used here.
  * SendAlert is still blocking. I thought it was not worth converting it to non-blocking.
mcs/class/Mono.Security/Mono.Security.Protocol.Tls/RecordProtocol.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslClientStream.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslServerStream.cs
mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslStreamBase.cs
mcs/class/System/System.Net/HttpWebRequest.cs
mcs/class/System/System.Net/WebConnectionStream.cs