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

No Timeout after DATA #226

Open
tinohager opened this issue Aug 27, 2024 · 2 comments
Open

No Timeout after DATA #226

tinohager opened this issue Aug 27, 2024 · 2 comments

Comments

@tinohager
Copy link
Contributor

tinohager commented Aug 27, 2024

When the session reaches the DATA part it can stay open forever there is no timeout that would close the session here. This allows the connection to remain open forever. I think it would make sense to be able to define an overall timeout for a session.

I think if we create a LinkedTokenSource in the SmtpSession with a timeout we could easily solve the problem.

async Task ExecuteAsync(SmtpSessionContext context, CancellationToken cancellationToken)

@martinguenther
Copy link

I want to vote for this issue. We've just recently had a problem which went down to this. On the given day, Microsoft seemed to have a problem in it's SMTP transport. On a percentage of the connections, after the DATA command, no data was sent. The connections stayed open infinitely which resulted in many open connections on our side (which uses SmtpServer).

We tackled it in ReadUntilAsync of PipeReaderExtensions, by adding a LinkedTokenSource.

I further want to add some of my findings to clarify why the problem arises.

On creation of the duplex pipe in EndpointListener

stream.ReadTimeout = (int)_endpointDefinition.ReadTimeout.TotalMilliseconds;

the ReadTimeout is set, which is meant to set "The timeout on each individual buffer read".

TimeSpan ReadTimeout { get; }

The thing is, that ReadTimeout of the underlying NetworkStream does not affect ReadAsync which is being used by SmtpServer. It only affects synchronous reads.

From the MS docs:

This property affects only synchronous reads performed by calling the Read method. This property does not affect asynchronous reads performed by calling the BeginRead or ReadAsync method.

I assume the ReadTimeout property of the IEndpointDefinition was supposed to handle this. But it does not, due to the nature of async reads.

It could be a solution to use the ReadTimeout of IEndpointDefinition to create a LinkedTokenSource and pass it on to the ReadAsync, down in ReadUntilAsync of PipeReaderExtensions. But, possibly there are other places too, which I have not yet found, so therefore, SmtpSession seems to be a better place, as suggested by @tinohager.

There is a pull request (#213) from @boba2fett which addresses this, in this commit f51e1fc.

Let me know if, and how, I can support on this.

@tinohager
Copy link
Contributor Author

fixed with 11.0.0-beta1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants