-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
SmtpConnection: fix Socket not getting Disposed when LingerState cannot be set. #428
Conversation
{ | ||
_tcpClient.LingerState = new LingerOption(true, 0); | ||
} | ||
catch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephentoub should I change the PR so we can figure out what exact exception gets thrown here? Or do we keep the general catch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference would be to catch the most specific exception possible, though the risk here is admittedly minimal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the exception something other than derived from System.Exception? Otherwise, why not just write catch (Exception)
?
But I agree it is useful to understand what's going on here. I would expect the exception is probably a SocketException.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should I change the PR so we can figure out what exact exception gets thrown here?
My preference is to catch just the exception types we expect. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scalablecory @davidsh @scalablecory I have to change the PR so we know what exception gets thrown here.
I'll revert this try-catch, and also remove the general try-catch in SmtpClient.Abort
. That should surface the exception.
We can give it a couple of test runs here. But since the issue doesn't happen often, probably we'll have to merge and wait for some time until it shows up in CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks fine. How reasonable would it be to write a test that exercises this?
{ | ||
_tcpClient.LingerState = new LingerOption(true, 0); | ||
} | ||
catch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference would be to catch the most specific exception possible, though the risk here is admittedly minimal.
2c2c2b8
to
57df602
Compare
57df602
to
62f67c6
Compare
I've updated the PR so instead of hanging, we should see the exception show up in CI now.
Though not a 100% test, the occasional failures in CI mean there is some coverage. |
@dotnet/ncl This is good to merge, and will help surface the exception we should catch. |
Hello @stephentoub! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Fixes https://github.com/dotnet/corefx/issues/40711