Describe the bug
DisconnectAsync can block when packets to a previously functioning session are suddenly dropped. Despite many attempts, I'm unable to get a cancellation token to end the task by setting a timer with CancelAfter.
I have a process which terminates a client session as such:
var client = new SmtpClient ();
.... mail processing here...
// Send and close
await client.SendAsync(mimeMessage).ConfigureAwait(false);
await client.DisconnectAsync(true).ConfigureAwait(false);
Occasionally, this job will hang -- typically always while connecting to an office365.com MTA. I'm unable to reproduce the behavior in production, and resorted to creating an artificial experience with packet filtering on a FreeBSD-based mail server. When dropping packets from the client just prior to the invocation of DisconnectAsync, my client session never ends. I attempted to rectify by passing a Cancellation Token to DisconnectAsync, but the connection continued to hang indefinitely. Calling instead Disconnect(true), it appears the session will close when the stream timeout is reached. (i.e. to whatever value I've set client.Timeout)
To Reproduce
Steps to reproduce the behavior:
- Create a new SmtpClient connection to a remote mail server.
- Prior to calling
DisconnectAsync(), sleep for 10 seconds
- While MailKit SMTP client process sleeps, use a firewall to drop packets from the client to the mail server.
- For my tests, I used the FreeBSD packet filtering abilities, but I could have used any intermediate firewall. e.g.
sudo ipfw add 1000 drop ip from me to <client IP address> src-port 25
- See session not close
Expected behavior
Expected would be the session to close after the default 120 second timeout, or allow a cancellation token to abort the task.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
Describe the bug
DisconnectAsync can block when packets to a previously functioning session are suddenly dropped. Despite many attempts, I'm unable to get a cancellation token to end the task by setting a timer with
CancelAfter.I have a process which terminates a client session as such:
Occasionally, this job will hang -- typically always while connecting to an office365.com MTA. I'm unable to reproduce the behavior in production, and resorted to creating an artificial experience with packet filtering on a FreeBSD-based mail server. When dropping packets from the client just prior to the invocation of DisconnectAsync, my client session never ends. I attempted to rectify by passing a Cancellation Token to DisconnectAsync, but the connection continued to hang indefinitely. Calling instead
Disconnect(true), it appears the session will close when the stream timeout is reached. (i.e. to whatever value I've setclient.Timeout)To Reproduce
Steps to reproduce the behavior:
DisconnectAsync(), sleep for 10 secondssudo ipfw add 1000 drop ip from me to <client IP address> src-port 25Expected behavior
Expected would be the session to close after the default 120 second timeout, or allow a cancellation token to abort the task.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.