Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SmtpClientTest Assertion Fail Fix #76361

Merged
merged 15 commits into from
Oct 24, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Win32.SafeHandles;
using System.Reflection;
using System.Collections;
using System.Threading;

namespace System.Net.Sockets
{
Expand Down Expand Up @@ -108,7 +109,7 @@ internal void ReplaceHandleIfNecessaryAfterFailedConnect()
SocketError errorCode = ReplaceHandle();
if (errorCode != SocketError.Success)
{
throw new SocketException((int) errorCode);
throw new SocketException((int)errorCode);
}

_handle.LastConnectFailed = false;
Expand Down Expand Up @@ -137,14 +138,22 @@ internal SocketError ReplaceHandle()

// Then replace the handle with a new one
SafeSocketHandle oldHandle = _handle;
SocketError errorCode = SocketPal.CreateSocket(_addressFamily, _socketType, _protocolType, out _handle);
SocketError errorCode = SocketPal.CreateSocket(_addressFamily, _socketType, _protocolType, out SafeSocketHandle newHandle);
Volatile.Write(ref _handle, newHandle);
liveans marked this conversation as resolved.
Show resolved Hide resolved
oldHandle.TransferTrackedState(_handle);
oldHandle.Dispose();

if (errorCode != SocketError.Success)
{
return errorCode;
}

if (Volatile.Read(ref _disposed) != 0)
{
_handle.Dispose();
liveans marked this conversation as resolved.
Show resolved Hide resolved
throw new ObjectDisposedException(GetType().FullName);
}

// And put back the copied settings. For DualMode, we use the value stored in the _handle
// rather than querying the socket itself, as on Unix stacks binding a dual-mode socket to
// an IPv6 address may cause the IPv6Only setting to revert to true.
Expand Down