-
Notifications
You must be signed in to change notification settings - Fork 5k
Support UnixDomainSocketEndPoint on Windows #27631
Conversation
@@ -28,108 +22,5 @@ static UnixDomainSocketEndPoint() | |||
Debug.Assert(s_nativePathOffset + s_nativePathLength <= s_nativeAddressSize, "Expected address size to include all of the path length"); | |||
Debug.Assert(s_nativePathLength >= 92, "Expected max path length to be at least 92"); // per http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_un.h.html | |||
} | |||
|
|||
public UnixDomainSocketEndPoint(string path) |
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.
All of this code just moved to the other partial class, with very few changes. I'll point them out individually.
if (!s_udsSupported.Value) | ||
{ | ||
throw new PlatformNotSupportedException(); | ||
} |
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 check is obviously new.
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.
Would it make sense to do this at the beginning of the constructor?
In reply to: 171722160 [](ancestors = 171722160)
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 thinning was that we want to make sure all the arguments are valid regardless of whether support is currently there. I could go either way, though.
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.
Ok, I can understand that reasoning. Just wanted to make sure.
|
||
public override SocketAddress Serialize() | ||
{ | ||
var result = new SocketAddress(AddressFamily.Unix, s_nativeAddressSize); |
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.
The length changed from s_nativePathOffset + _encodedPath.Length
to s_nativeAddressSize
.
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.
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.
Because it needs to match the native type in size/layout; otherwise if the native implementation dereferences, it can AV and other such things, and the native implementation may also do a size check. Basically it's dangerous to use anything smaller than the corresponding native definition.
{ | ||
bytesRead = await client.ReceiveAsync(new ArraySegment<byte>(buffer), SocketFlags.None); | ||
Assert.InRange(bytesRead, 1, writeBuffer.Length - readData.Length); |
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 changed this because in my build there are some issues with shutdown, and the test would sometimes hang.
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 - For the hang, as discussed offline, couple of similar bugs were fixed in the release branch. If you can give it a try on a recent build.
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.
If you can give it a try on a recent build.
I will, thanks.
Did you punt on the SAEA issue? |
Should we add a static OSSupportsUnixDomainSockets, like OSSupportsIPv4/6? |
@dotnet/dnceng, can you help me to understand what failed in https://ci3.dot.net/job/dotnet_corefx/job/master/job/linux-TGroup_netcoreapp+CGroup_Release+AGroup_x64+TestOuter_false_prtest/9488/consoleText? Some kind of infrastructure issue? |
Yes. There's an easy workaround if you think it's worthwhile, which is to essentially just do the same thing that's done in the other asynchronous connects and fall back to a synchronous connect for things other than DnsEndPoint and IPEndPoint.
I think that'd be reasonable. We can open an issue. |
@@ -8,18 +8,12 @@ | |||
namespace System.Net.Sockets | |||
{ | |||
/// <summary>Represents a Unix Domain Socket endpoint as a path.</summary> | |||
public sealed class UnixDomainSocketEndPoint : EndPoint | |||
public sealed partial class UnixDomainSocketEndPoint : EndPoint |
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 had no idea we made this public
|
||
// Pathname socket addresses should be null-terminated. | ||
// Linux abstract socket addresses start with a zero byte, they must not be null-terminated. | ||
bool isAbstract = IsAbstract(path); |
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.
Does Windows support abstract socket addresses? Will it fail later if one is passed in?
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.
It does.
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.
Oh, I see the test now. Nice!
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.
Yes, Windows unix sockets supports abstract addresses, but, it does not support the autobind feature available in linux (see man7 unix).
// Some Windows will. | ||
try | ||
{ | ||
new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified).Dispose(); |
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 assumes that our product code is doing the right thing. Would it be better to P/Invoke into Windows directly to see if it is supported?
Or is their some other way to ask Windows if it is supported?
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.
To check whether a given socket domain, type or protocol combo is supported, the best thing is to call the socket
routine and check the return value.
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.
To check whether a given socket domain, type or protocol combo is supported, the best thing is to call the socket routine and check the return value.
That's essentially what this code is doing, just via the .NET Socket type.
But to Eric's point, sure, I can just P/Invoke directly.
@@ -443,5 +442,29 @@ private static string GetRandomNonExistingFilePath() | |||
|
|||
return result; | |||
} | |||
|
|||
private static bool PlatformDoesntSupportUnixDomainSockets => s_platformSupportsUnixDomainSockets.Value; |
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 there be a !
here?
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.
Yes, that's why the Windows CI failed. :)
@stephentoub we had a total outage of telemetry processing, which is resolved now but was causing the Helix API to not reflect recently started jobs. Once the Jenkins plugin waited 15 minutes, it failed with the java.lang.NullPointerException as you noted (generally the wait between sending work and showing up in the API is < 5 seconds). This was dotnet/core-eng#2805. |
Windows is adding support for Unix domain sockets, and it's easy to enable that support via our new UnixDomainSocketEndPoint type.
903f3cf
to
afeb431
Compare
* Support UnixDomainSocketEndPoint on Windows Windows is adding support for Unix domain sockets, and it's easy to enable that support via our new UnixDomainSocketEndPoint type. * Address PR feedback Commit migrated from dotnet/corefx@421ce7b
Windows is adding support for Unix domain sockets, and it's easy to enable that support via our new UnixDomainSocketEndPoint type.
Fixes https://github.com/dotnet/corefx/issues/27542
cc: @eerhardt, @danmosemsft, @geoffkizer, @sunilmut, @tmds