forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SmtpClient: fix Timeout for low values (dotnet/corefx#37462)
* SmtpClient: fix Timeout for low values The timeout is triggered from a Timer. There were two race conditions: - The timer event could occur before there was a connection to abort. - The connection abort performs a TcpClient.Dispose, which may not work when there is a TcpClient.Connect occurring simultaneously. * TCPClient: make Dispose thread-safe * Fix NullReferenceException from _networkstream.Close * SmtpTransport: fix racy aborted detection * TestZeroTimeout: skip on .NET Framework * PR feedback * Don't null out socket on Dispose to let ODE propagate from Socket * Fix merge * Run TestZeroTimeout test on Linux too * Add back ODE to TcpClient.Connect(IPEndPoint) * Add comment about why we're disposing the socket * PR feedback Commit migrated from dotnet/corefx@807a18d
- Loading branch information
1 parent
c5d6605
commit 1bcdf38
Showing
5 changed files
with
99 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net.NetworkInformation; | ||
using System.Net.Sockets; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
@@ -315,6 +316,25 @@ public void TestMailDelivery() | |
} | ||
} | ||
|
||
[Fact] | ||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET Framework has a bug and may not time out for low values")] | ||
[PlatformSpecific(~TestPlatforms.OSX)] // on OSX, not all synchronous operations (e.g. connect) can be aborted by closing the socket. | ||
public void TestZeroTimeout() | ||
{ | ||
using (Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) | ||
{ | ||
serverSocket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); | ||
serverSocket.Listen(1); | ||
|
||
SmtpClient smtpClient = new SmtpClient("localhost", (serverSocket.LocalEndPoint as IPEndPoint).Port); | ||
smtpClient.Timeout = 0; | ||
|
||
MailMessage msg = new MailMessage("[email protected]", "[email protected]", "hello", "test"); | ||
Assert.Throws<SmtpException>(() => smtpClient.Send(msg)); | ||
} | ||
} | ||
|
||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET Framework has a bug and could hang in case of null or empty body")] | ||
[Theory] | ||
[InlineData("howdydoo")] | ||
[InlineData("")] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters