Closed
Description
To repro, connect to any SSL endpoint (127.0.0.1:5001 in the example below) and attempt a 0-byte write:
using System;
using System.IO;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var x509certificate = new X509Certificate2(@"testCert.pfx", "testPassword");
using (var client = new TcpClient())
{
client.ConnectAsync("127.0.0.1", 5001).Wait();
using (var sslStream = new SslStream(client.GetStream(), false, (sender, certificate, chain, errors) => true,
(sender, host, certificates, certificate, issuers) => x509certificate))
{
sslStream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false).Wait();
sslStream.WriteAsync(new byte[0], 0, 0, CancellationToken.None).Wait();
}
}
}
}
}
It just hangs there.
We found this issue in Kestrel, which is experiencing test failures because of this (aspnet/KestrelHttpServer#1193 (comment)). Kestrel is hanging in https://github.com/aspnet/KestrelHttpServer/blob/4337d2a4a751ee7ccb0e0c460670c0abd044d040/src/Microsoft.AspNetCore.Server.Kestrel/Filter/Internal/StreamSocketOutput.cs#L63 when we do a 0-byte write to flush.