Repository navigation
Description
Description
I work on an iOS app (currently Xamarin iOS/.NET 4.8) that uses unix domain sockets. Trying to port to .NET 8, I noticed that the constructor of UnixDomainSocketEndPoint now throws a PlatformNotSupportedException.
Reproduction Steps
var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
fullPath = Path.Join(
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"my.sock");
if (File.Exists(fullPath))
File.Delete(fullPath);
var endpoint = new UnixDomainSocketEndPoint(fullPath); // throws PlatformNotSupportedException on .NET 8
socket.Bind(endpoint);
socket.Listen(10);
Expected behavior
Expected to get an instance of UnixDomainSocketEndPoint (as with the older framework)
Actual behavior
Thrown PlatformNotSupportedException
Regression?
Works on .NET 4.8/Xamarin.iOS
Known Workarounds
Pull a copy of the UnixDomainSocketEndPoint code into the project, then comment out the platform check (along with some other minor changes to make it compile)
Verified that this works within my iOS app.
Configuration
net8.0-ios
Other information
SocketProtocolSupportPal.Unix.cs contains a comment about AF_UNIX sockets not working on iOS, then explicitly denies support:
internal static partial class SocketProtocolSupportPal
{
private const int DgramSocketType = 2;
private static unsafe bool IsSupported(AddressFamily af)
{
// Check for AF_UNIX on iOS/tvOS. The OS claims to support this, but returns EPERM on bind.
// We should explicitly set the return here to false, to avoid giving a false impression.
if (af == AddressFamily.Unix && (OperatingSystem.IsTvOS() || (OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst())))
{
return false;
}
That claim is not consistent with my experience.
Activity
steveisok commentedon Dec 18, 2023
@directhex #73374 marked this as PNSE. Can you confirm this is still true?
@lnbot were you using simulator or device to test this?
lnbot commentedon Dec 18, 2023
I'm running this on device.
Our usage of unix domain sockets in this app also has been live in the app store for several years.
lnbot commentedon Dec 18, 2023
Your referenced issue mentions that binding the socket failed in
NSTemporaryDirectory().However, our use case is putting the socket in an App Group shared container.
Maybe this accounts for the different experiences?
akoeplinger commentedon Dec 19, 2023
Looks like this is indeed allowed in App Groups according to https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_application-groups
We should remove our PNSE.
aurimasc commentedon Sep 2, 2026
Modifying the following condition to enable iOS makes things work. iOS restricts paths to which domain sockets can be bind, but they do work.
runtime/src/libraries/Common/src/System/Net/SocketProtocolSupportPal.Unix.cs
Line 17 in 36ef186
shatanov commentedon Sep 2, 2026
I'd like to work on this issue.
I plan to verify Unix domain socket behavior on a physical iOS device using an allowed sandbox/App Group directory, then remove the global iOS restriction in
SocketProtocolSupportPal.Unix.csand add aregression test.
Before I start implementing the fix, could you please confirm that this is the right direction: enable
AddressFamily.Unixon iOS while keeping the explicit restrictions for tvOS and WASI?aurimasc commentedon Sep 3, 2026
I haven't tried tvOS, but for iOS removing the guard allowed me to create and bind domain socket.
akoeplinger commentedon Sep 3, 2026
@shatanov according to the docs it applies to tvOS as well so I'd enable it for the two platforms.
A couple existing tests check for
Socket.OSSupportsUnixDomainSockets, those will start to run now. I'd check and make sure that they use a path which is allowed on iOS/tvOS.Enable Unix domain sockets on iOS and tvOS
Enable Unix domain sockets on iOS and tvOS (#135167)