You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Per the documentation at SmtpClient.Dispose this method should send QUIT:
Sends a QUIT message to the SMTP server, gracefully ends the TCP connection, and releases all resources used by the current instance of the SmtpClient class.
However when using in .NET Core, this does not appear to be the case.
@davidsh would it make sense to implement DisposeAsync on SmtpClient, given that network packets would be sent (and flushed) when disposed? /cc @stephentoub
There is no SmtpClient.DisposeAsync() method on the API. In fact, this method was added to .NET Framework long before Task async pattern was available. So, it would need to be implemented as a blocking/synchronous API.
@davidsh sure, but since dotnet/corefx#32665 introduced IAsyncDisposable, could SmtpClient be updated to implement the async disposal API for frameworks that support it?
Prior to this being worked on, is it possible to change/remove the XML documentation from the SmtpClient.Dispose() method? Right now it's misleading and adds to confusion.
Prior to this being worked on, is it possible to change/remove the XML documentation from the SmtpClient.Dispose() method? Right now it's misleading and adds to confusion.
Can you be specific about what is wrong with the current documentation? Are you referring to documentation here? Or someplace else?
Are you showing the screenshot from Visual Studio or some other tool?
In general, the documentation is correct. That is how the API should work. And on .NET Framework, the API works correctly. We don't change the documentation for a bug like this. This is a product bug with .NET Core and will be fixed in a future release.
From Visual Studio. I understand that this is how the API is supposed to work, but if it doesn't and it's a known bug it should be documented/referenced somewhere. Especially if the fix doesn't make it into the 3.0 release. Just my 2¢ worth.
is there any practical impact of this @mguinness ?
We need to fix this same as .NET Framework. Without sending the QUIT, the TCP connection to the server is not closed cleanly. So, this results in connections with CLOSE_WAIT and can eat up local ephemeral ports.
Is there any workaround to explicitly close connections before disposing? Is it possible to use the CloseConnectionGroup(string connectionGroupName) method of the ServicePoint property to achieve this?
Is stopping the process the only way to release these?
Most likely.
Is there any workaround to explicitly close connections before disposing? Is it possible to use the CloseConnectionGroup(string connectionGroupName) method of the ServicePoint property to achieve this?
Are you using an explicit 'connectionGroupName' with the SmtpClient API? If not, then you won't be able to close the connections easily. And some of those .NET Framework ServicePoint related APIs are internal and not public. And I don't think attempting to use reflection is possible/recommended with Windows PowerShell.
Given that, it should be difficult to get into a situation where sending QUIT would block.
It's not clear to me why inflight data send and quit are "related" to blocking...I mean AFAIK every data send to network can block, unrelated to previous send data, am I wrong?I mean I can send message and at the end block on send quit. My concern is not related to dispose that wait for the inflight message, but the normal workflow send->quit.
Block in the way that an async send could scale better than sync one. FYI fix is ready if you want take a look #683
It's not clear to me why inflight data send and quit are "related" to blocking...I mean AFAIK every data send to network can block, unrelated to previous send data, am I wrong?
@Tratcher's assumption is that SmtpClient will not be used in a way which would fill up your TCP send buffer. In this case, writing a QUIT will just write to the same buffer without blocking.
Note, the spec actually calls for more than QUIT -- it calls for us to wait for the reply. So, if we really wanted to be compatible, we would be blocking regardless of SmtpClient usage.
Are there plans to backport this to 3.1, or will we need to wait for .NET 5?
There are no plans for backport to 3.1. But I'll let @karelz or @danmosemsft comment on that. We would need to see many customers impacted in order to considering a backport.
As @davidsh mentioned, it depends on impact - how big, how many customers, how hard to workaround.
So far, this didn't seem to be absolutely terrible adoption blocker IMO.
ghost locked as resolved and limited conversation to collaborators on Dec 14, 2020
Activity
davidsh commentedon Jan 26, 2019
This is a likely a product bug in .NET Core.
nil4 commentedon Jan 26, 2019
@davidsh would it make sense to implement
DisposeAsynconSmtpClient, given that network packets would be sent (and flushed) when disposed? /cc @stephentoubdavidsh commentedon Jan 26, 2019
There is no SmtpClient.DisposeAsync() method on the API. In fact, this method was added to .NET Framework long before Task async pattern was available. So, it would need to be implemented as a blocking/synchronous API.
nil4 commentedon Jan 26, 2019
@davidsh sure, but since dotnet/corefx#32665 introduced
IAsyncDisposable, could SmtpClient be updated to implement the async disposal API for frameworks that support it?davidsh commentedon Jan 26, 2019
Yes, but that would be a separate issue that would need to be opened. And it requires an API change/review process as well.
mguinness commentedon Jan 29, 2019
Prior to this being worked on, is it possible to change/remove the XML documentation from the SmtpClient.Dispose() method? Right now it's misleading and adds to confusion.
davidsh commentedon Jan 29, 2019
Can you be specific about what is wrong with the current documentation? Are you referring to documentation here? Or someplace else?
mguinness commentedon Jan 30, 2019
From the <summary> tag used by Intellisense.
davidsh commentedon Jan 30, 2019
Are you showing the screenshot from Visual Studio or some other tool?
In general, the documentation is correct. That is how the API should work. And on .NET Framework, the API works correctly. We don't change the documentation for a bug like this. This is a product bug with .NET Core and will be fixed in a future release.
mguinness commentedon Jan 30, 2019
From Visual Studio. I understand that this is how the API is supposed to work, but if it doesn't and it's a known bug it should be documented/referenced somewhere. Especially if the fix doesn't make it into the 3.0 release. Just my 2¢ worth.
wfurt commentedon Aug 20, 2019
is there any practical impact of this @mguinness ?
If so, could you post simple repro with description?
davidsh commentedon Aug 20, 2019
We need to fix this same as .NET Framework. Without sending the QUIT, the TCP connection to the server is not closed cleanly. So, this results in connections with CLOSE_WAIT and can eat up local ephemeral ports.
wfurt commentedon Aug 20, 2019
OK. We can look at .NET Framework. Interesting part is when Dispose() is called while still sending email body.
mguinness commentedon Oct 22, 2019
You can see the ports that are tied up using the following PowerShell command. Is stopping the process the only way to release these?
Get-NetTCPConnection -State CloseWait -RemotePort 587 | Format-Table -Property OwningProcess,LocalPort,CreationTimeIs there any workaround to explicitly close connections before disposing? Is it possible to use the
CloseConnectionGroup(string connectionGroupName)method of the ServicePoint property to achieve this?davidsh commentedon Oct 22, 2019
Most likely.
Are you using an explicit 'connectionGroupName' with the SmtpClient API? If not, then you won't be able to close the connections easily. And some of those .NET Framework ServicePoint related APIs are internal and not public. And I don't think attempting to use reflection is possible/recommended with Windows PowerShell.
51 remaining items
MarcoRossignoli commentedon Dec 17, 2019
It's not clear to me why inflight data send and quit are "related" to blocking...I mean AFAIK every data send to network can block, unrelated to previous send data, am I wrong?I mean I can send message and at the end block on send quit. My concern is not related to dispose that wait for the inflight message, but the normal workflow send->quit.
Block in the way that an async send could scale better than sync one. FYI fix is ready if you want take a look #683
scalablecory commentedon Dec 17, 2019
@Tratcher's assumption is that
SmtpClientwill not be used in a way which would fill up your TCP send buffer. In this case, writing a QUIT will just write to the same buffer without blocking.tmds commentedon Dec 17, 2019
If you want to send QUIT in Dispose, set
Socket.Blockingtofalsebefore sending. That avoids the blocking behavior.scalablecory commentedon Dec 17, 2019
Note, the spec actually calls for more than QUIT -- it calls for us to wait for the reply. So, if we really wanted to be compatible, we would be blocking regardless of
SmtpClientusage.MarcoRossignoli commentedon Dec 17, 2019
Yep per spec we should wait reply.
davidsh commentedon Feb 26, 2020
Fixed by PR #683
mguinness commentedon Feb 27, 2020
Thanks to Marco for the PR. @davidsh Are there plans to backport this to 3.1, or will we need to wait for .NET 5?
davidsh commentedon Feb 27, 2020
There are no plans for backport to 3.1. But I'll let @karelz or @danmosemsft comment on that. We would need to see many customers impacted in order to considering a backport.
karelz commentedon Feb 27, 2020
As @davidsh mentioned, it depends on impact - how big, how many customers, how hard to workaround.
So far, this didn't seem to be absolutely terrible adoption blocker IMO.