From: Ahmet Ibrahim AKSOY Date: Mon, 24 Oct 2022 12:23:09 +0000 (+0200) Subject: SmtpClientTest Assertion Fail Fix (#76361) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~5811 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c092a76137864994af299d2c2195453f1d5e6b33;p=platform%2Fupstream%2Fdotnet%2Fruntime.git SmtpClientTest Assertion Fail Fix (#76361) * Eliminate temporary -1 on Socket.Unix.cs --- diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs index ec5d17c..2f93a77 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs @@ -8,6 +8,7 @@ using System.Runtime.Versioning; using Microsoft.Win32.SafeHandles; using System.Reflection; using System.Collections; +using System.Threading; namespace System.Net.Sockets { @@ -108,7 +109,7 @@ namespace System.Net.Sockets SocketError errorCode = ReplaceHandle(); if (errorCode != SocketError.Success) { - throw new SocketException((int) errorCode); + throw new SocketException((int)errorCode); } _handle.LastConnectFailed = false; @@ -137,14 +138,22 @@ namespace System.Net.Sockets // 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); oldHandle.TransferTrackedState(_handle); oldHandle.Dispose(); + if (errorCode != SocketError.Success) { return errorCode; } + if (Volatile.Read(ref _disposed) != 0) + { + _handle.Dispose(); + 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.