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

use Task.Run to execute SmtpClient #74910

Merged
merged 3 commits into from
Sep 12, 2022
Merged

use Task.Run to execute SmtpClient #74910

merged 3 commits into from
Sep 12, 2022

Conversation

wfurt
Copy link
Member

@wfurt wfurt commented Sep 1, 2022

I'm not sure why #74545 did not work. we got one more test hanging instance after it.
After looking at the Mail code the SendMailAsync actually does fair amount of synchronous processing before returning the Task.
I'm not sure if there is better way to do it @stephentoub but I'm pushing that to the thread-pool to be sure the code before it and final await can execute.

This is only one test in Mail test suite using the ManualResetEvent. I did look at and it seems ok to me. We basically block completion so the client has chance to cancel.

contributes to #73447

@wfurt wfurt added area-System.Net test-enhancement Improvements of test source code labels Sep 1, 2022
@wfurt wfurt requested review from stephentoub and a team September 1, 2022 07:18
@wfurt wfurt self-assigned this Sep 1, 2022
@ghost
Copy link

ghost commented Sep 1, 2022

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

Issue Details

I'm not sure why #74545 did not work. we got one more test hanging instance after it.
After looking at the Mail code the SendMailAsync actually does fair amount of synchronous processing before returning the Task.
I'm not sure if there is better way to do it @stephentoub but I'm pushing that to the thread-pool to be sure the code before it and final await can execute.

This is only one test in Mail test suite using the ManualResetEvent. I did look at and it seems ok to me. We basically block completion so the client has chance to cancel.

contributes to #73447

Author: wfurt
Assignees: wfurt
Labels:

area-System.Net, test-enhancement

Milestone: -

@@ -473,7 +473,7 @@ public async Task SendMailAsync_CanBeCanceled_CancellationToken()

var message = new MailMessage("[email protected]", "[email protected]", "Foo", "Bar");

Task sendTask = client.SendMailAsync(message, cts.Token);
Task sendTask = Task.Run(() => client.SendMailAsync(message, cts.Token));
Copy link
Member

Choose a reason for hiding this comment

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

I'm not clear on what these Task.Runs are meant to help. What's the theory about the problem and how this solves it?

If the issue is that the operation ends up completing before we get a chance to cancel it, we should change the loopback server to not have a race condition: rather than "some fake latency", make it configurable, and here make it infinite, such that no matter how long it takes for us to get to the cts.Cancel call, we know for sure that the operation won't have completed yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

The whole test hangs and I have no visibility why. When this happens Helix just kills the suite and we get no information. In #74545 I tried to add cap on how long we await for tasks - but that does not seems to be sufficient. So it feels we get stuck somewhere while creating the sendTask . So the goal is to put this to background so we can get to the await bellow and timeout ... and possibly collect some information. this is not attempt to fix the root cause.

Copy link
Member

Choose a reason for hiding this comment

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

this is not attempt to fix the root cause.

Got it, ok, thanks.

Copy link
Member

@rzikm rzikm left a comment

Choose a reason for hiding this comment

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

LGTM

@wfurt wfurt merged commit 4cda393 into dotnet:main Sep 12, 2022
@wfurt wfurt deleted the run branch September 12, 2022 18:53
@ghost ghost locked as resolved and limited conversation to collaborators Oct 12, 2022
@karelz karelz added this to the 8.0.0 milestone Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net test-enhancement Improvements of test source code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants