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

Fix SMTP health checks not respecting timeout #1739

Merged
merged 3 commits into from
May 5, 2023
Merged

Fix SMTP health checks not respecting timeout #1739

merged 3 commits into from
May 5, 2023

Conversation

peterwurzinger
Copy link
Contributor

@peterwurzinger peterwurzinger commented Mar 11, 2023

What this PR does / why we need it:
The cancellation token in an SMTP handshake will be passed to the initial TCP connection as well, making it respect a given timeout.
It seems like this has already been an issue for IMAP connections, as there is a Test and the same Fix for that type of checks.

Which issue(s) this PR fixes:
#1738

Does this PR introduce a user-facing change?
At least I'm not aware of any.

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Unit tests passing
  • End-to-end tests passing

@sungam3r
Copy link
Collaborator

Thanks. Please look into #1740 as an example of how this can be done for modern TFMs. Let's pass cancellationToken down the call tree and use overloads that accept it. Use WithCancellationTokenAsync only as a fallback for other TFMs.

@peterwurzinger
Copy link
Contributor Author

peterwurzinger commented Mar 18, 2023

Alright, i finally had time for that. Please have a look if that is how you wanted it to be implemented.

But allow me a few additional notes:

  1. I had to leverage the CancellationToken all the way up to MailConnection.ConnectAsync as a parameter. That is not necessarily a problem, because there is then only one place to do this TFM-dance. BUT: ImapConnection is also derives from MailConnection, yet I did not touch its implementation within this PR to not mix things up. Imo it would absolutely make sense to pass the CancellationToken in IMAP connections as well.
  2. It now is a binary breaking change. Since ConnectAsync accepts a CancellationToken as default parameter, it doesn't break builds, yet if only the binary would be replaced during runtime, one would see runtime errors. (Don't know if somebody would really do that and use the "raw" MailConnection , but yeah...)
  3. There are quite a few places in the mail-specific check implementations, where a Cancellation token could be passed, or an async alternative could be used. e.g.
  • AuthenticateAsync
  • ExecuteCommand (yet I don't know if that is maybe intentional to keep commands as atomic operations)
  • AuthenticateAsClientAsync

Maybe you could share your thoughts on that.

@sungam3r
Copy link
Collaborator

It now is a binary breaking change

It doesn't matter for now since all packages are in 7.0.0-preview state.

@peterwurzinger
Copy link
Contributor Author

Fair enough, yes.

@sungam3r
Copy link
Collaborator

sungam3r commented May 1, 2023

@peterwurzinger Finally I returned to review this one.

AuthenticateAsync
ExecuteCommand (yet I don't know if that is maybe intentional to keep commands as atomic operations)
AuthenticateAsClientAsync

Yes, I'm fine having them all with Async suffix and accepting CancellationToken. Also place ArrayPool<byte>.Shared.Return(readBuffer); under finally in ExecuteCommand.

@peterwurzinger
Copy link
Contributor Author

Shall this be done within this PR, or shall I open a separate one? I guess it would touch not only the SMTP implementation, but also the IMAP check, therefore being probably a lot more than just fixing #1738

@peterwurzinger
Copy link
Contributor Author

@sungam3r I opened another PR to cover those additional chores:
#1812

@sungam3r sungam3r merged commit b2c70f5 into Xabaril:master May 5, 2023
@peterwurzinger peterwurzinger deleted the fix/smtp-timeout branch May 6, 2023 08:02
@sungam3r sungam3r mentioned this pull request Jul 30, 2023
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