Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit 4d1af96

Browse files
stephentoubPetermarcu
authored andcommitted
Fix SslStream.WriteAsync with 0-byte write (#13384)
A previous fix added an early exit when 0-byte writes aren't supported by the underlying SSL implementation. But in doing so, WriteAsync(..., 0) ends up returning a Task that never completes.
1 parent 11a75e6 commit 4d1af96

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/System.Net.Security/src/System/Net/SecureProtocols/SslStreamInternal.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ private void StartWriting(byte[] buffer, int offset, int count, AsyncProtocolReq
398398
{
399399
// If it's an empty message and the PAL doesn't support that,
400400
// we're done.
401-
return;
401+
break;
402402
}
403403

404404
// Request a write IO slot.

src/System.Net.Security/tests/FunctionalTests/SslStreamStreamToStreamTest.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void SslStream_StreamToStream_Successive_ClientWrite_Sync_Success()
9595

9696
[OuterLoop] // TODO: Issue #11345
9797
[Fact]
98-
public void SslStream_StreamToStream_Successive_ClientWrite_Sync_WithZeroBytes_Success()
98+
public void SslStream_StreamToStream_Successive_ClientWrite_WithZeroBytes_Success()
9999
{
100100
byte[] recvBuf = new byte[_sampleMsg.Length];
101101
VirtualNetwork network = new VirtualNetwork();
@@ -110,13 +110,15 @@ public void SslStream_StreamToStream_Successive_ClientWrite_Sync_WithZeroBytes_S
110110
Assert.True(result, "Handshake completed.");
111111

112112
clientSslStream.Write(Array.Empty<byte>());
113+
clientSslStream.WriteAsync(Array.Empty<byte>(), 0, 0).Wait();
113114
clientSslStream.Write(_sampleMsg);
114115

115116
serverSslStream.Read(recvBuf, 0, _sampleMsg.Length);
116117

117118
Assert.True(VerifyOutput(recvBuf, _sampleMsg), "verify first read data is as expected.");
118119

119120
clientSslStream.Write(_sampleMsg);
121+
clientSslStream.WriteAsync(Array.Empty<byte>(), 0, 0).Wait();
120122
clientSslStream.Write(Array.Empty<byte>());
121123

122124
serverSslStream.Read(recvBuf, 0, _sampleMsg.Length);

0 commit comments

Comments
 (0)