-
Notifications
You must be signed in to change notification settings - Fork 5.3k
PoC: retire internal SocketExceptionFactory #68918
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
Conversation
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
|
Tagging subscribers to this area: @dotnet/ncl Issue DetailsThis fixes #37150. I would like to get some feedback before dragging this to API review. There are actually two separate places where the internals exception would show up. Let's consider try {
Socket s1 = new Socket(SocketType.Stream, ProtocolType.Tcp);
s1.Connect(IPEndPoint.Parse("127.0.0.1:54321"));
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
try {
Socket s2 = new Socket(SocketType.Stream, ProtocolType.Tcp);
s2.ConnectAsync(IPEndPoint.Parse("127.0.0.1:54321")).GetAwaiter().GetResult();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
var foo = Dns.GetHostAddresses(Guid.NewGuid().ToString("N"));it would currently produce In Sockets, this differ for sync vs async. And we get internal exception for DNS errors. The DNS is easy to fix IMHO and it does not need API change. I can bring that forward if we want to. (fixes issue I hit with #67951) With this change we get so both sync & async Connect has same exception type with details and DNS failure is
|
| // but that's the least bad option right now. | ||
| } | ||
|
|
||
| public SocketException(int errorCode, EndPoint? endPoint) : this((SocketError)errorCode) |
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.
I think SocketException(int errorCode, string message) would be indeed more future-proof, and feels like a missing API regardless of the current issue, while storing an IPEndpoint feels like an arbitrary decision leading to a bunch of questions: what endpoint? remote? local? why not both? etc.
However, RemoteEndPoint.ToString() would always allocate but I'm not sure if that matters that much for failures.
Exception throwing is already very expensive, and there is a high chance that someone somewhere would log the message anyways, so I would just pass that string in every case.
|
@stephentoub can you please help make the decision on string vs. |
|
I think it should just take a |
This fixes #37150. I would like to get some feedback before dragging this to API review.
There are actually two separate places where the internals exception would show up. Let's consider
it would currently produce
In Sockets, this differ for sync vs async. And we get internal exception for DNS errors.
The DNS is easy to fix IMHO and it does not need API change. I can bring that forward if we want to. (fixes issue I hit with #67951)
For the socket exception I was wondering if we should take string instead of EndPoint as we can pass more information to it in the future. However,
RemoteEndPoint.ToString()would always allocate but I'm not sure if that matters that much for failures. If We are happy with EndPoint, I can create API proposal and drag it through review.With this change we get
so both sync & async Connect has same exception type with details and DNS failure is
SocketExceptionwith same details as before.