Skip to content

Commit 9523c73

Browse files
authored
Fix System.Net.Mail.Tests.SmtpClientTest.TestZeroTimeout (dotnet#116062)
1 parent e6d64b1 commit 9523c73

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpTransport.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ internal sealed class SmtpTransport
1919
private SmtpConnection? _connection;
2020
private readonly SmtpClient _client;
2121
private ICredentialsByHost? _credentials;
22+
private bool _shouldAbort;
2223

2324
private bool _enableSsl;
2425
private X509CertificateCollection? _clientCertificates;
@@ -90,6 +91,11 @@ internal Task GetConnectionAsync<TIOAdapter>(string host, int port, Cancellation
9091
lock (this)
9192
{
9293
_connection = new SmtpConnection(this, _client, _credentials, _authenticationModules);
94+
if (_shouldAbort)
95+
{
96+
_connection.Abort();
97+
}
98+
_shouldAbort = false;
9399
}
94100

95101
if (NetEventSource.Log.IsEnabled()) NetEventSource.Associate(this, _connection);
@@ -146,7 +152,14 @@ internal void Abort()
146152
{
147153
lock (this)
148154
{
149-
_connection?.Abort();
155+
if (_connection != null)
156+
{
157+
_connection.Abort();
158+
}
159+
else
160+
{
161+
_shouldAbort = true;
162+
}
150163
}
151164
}
152165
}

0 commit comments

Comments
 (0)