Skip to content

Fix SmtpClientTest zero timeout hang #116062

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

Merged
merged 1 commit into from
May 29, 2025
Merged

Conversation

rzikm
Copy link
Member

@rzikm rzikm commented May 28, 2025

This reverts part of the SmtpTransport changes from #115722 which caused timeouts and test suite crashes of System.Net.Mail.Tests.SmtpClientTest.TestZeroTimeout test.

Zero timeout values are weird, but for now the easier step is to preserve the old behavior than consider making breaking changes.

@Copilot Copilot AI review requested due to automatic review settings May 28, 2025 09:25
@rzikm rzikm requested a review from a team May 28, 2025 09:26
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR restores the previous SmtpTransport abort behavior to avoid hangs when a zero timeout is specified, preserving compatibility for the existing TestZeroTimeout test.

  • Introduces a _shouldAbort flag to defer aborting until after the connection is established
  • Updates Abort() and GetConnectionAsync to use the deferred abort logic
Comments suppressed due to low confidence (1)

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

  • Consider adding a unit test to cover the scenario where Abort() is called before GetConnectionAsync() has created a connection to ensure the deferred abort logic behaves as expected and avoids regressions.
private bool _shouldAbort;

@@ -19,6 +19,7 @@ internal sealed class SmtpTransport
private SmtpConnection? _connection;
private readonly SmtpClient _client;
private ICredentialsByHost? _credentials;
Copy link
Preview

Copilot AI May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an inline comment or XML doc summary for _shouldAbort to explain that this flag defers the abort until after the connection is established, clarifying its purpose for future maintainers.

Suggested change
private ICredentialsByHost? _credentials;
private ICredentialsByHost? _credentials;
// Indicates whether the operation should be aborted. This flag defers the abort until after the connection is established.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@rzikm rzikm merged commit 9523c73 into dotnet:main May 29, 2025
85 of 87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants