state.Connected = true;
state.ConnectTcs!.SetResult(MsQuicStatusCodes.Success);
+ state.ConnectTcs = null;
}
return MsQuicStatusCodes.Success;
throw new Exception($"Unsupported remote endpoint type '{_remoteEndPoint.GetType()}'.");
}
- _state.ConnectTcs = new TaskCompletionSource<uint>(TaskCreationOptions.RunContinuationsAsynchronously);
+ // We store TCS to local variable to avoid NRE if callbacks finish fast and set _state.ConnectTcs to null.
+ var tcs = _state.ConnectTcs = new TaskCompletionSource<uint>(TaskCreationOptions.RunContinuationsAsynchronously);
try
{
throw;
}
- return new ValueTask(_state.ConnectTcs.Task);
+ return new ValueTask(tcs.Task);
}
private ValueTask ShutdownAsync(
if (state.ConnectTcs != null)
{
- state.ConnectTcs.SetException(ex);
- state.ConnectTcs = null;
+ // This is opportunistic if we get exception and have ability to propagate it to caller.
+ state.ConnectTcs.TrySetException(ex);
state.Connection = null;
+ state.ConnectTcs = null;
}
else
{
}
[Fact]
- [ActiveIssue("https://github.com/dotnet/runtime/issues/56263")]
public async Task ConnectWithCertificateCallback()
{
X509Certificate2 c1 = System.Net.Test.Common.Configuration.Certificates.GetServerCertificate();
}
[Fact]
- [ActiveIssue("https://github.com/dotnet/runtime/issues/56454")]
public async Task ConnectWithCertificateForDifferentName_Throws()
{
(X509Certificate2 certificate, _) = System.Net.Security.Tests.TestHelper.GenerateCertificates("localhost");