Skip to content

UnixDomainSocketEndPoint no longer constructable on iOS (.NET 8) #96143

Closed

Description

@lnbot

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

  1. ghost added
    untriaged
    on Dec 18, 2023
  2. steveisok commented on Dec 18, 2023

    @steveisok
    Member

    @directhex #73374 marked this as PNSE. Can you confirm this is still true?

    @lnbot were you using simulator or device to test this?

  3. lnbot commented on Dec 18, 2023

    @lnbot
    Author

    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.

  4. lnbot commented on Dec 18, 2023

    @lnbot
    Author

    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?

  5. akoeplinger commented on Dec 19, 2023

    @akoeplinger
    Member

    Looks like this is indeed allowed in App Groups according to https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_application-groups

    Apps within a group can communicate with other members in the group using IPC mechanisms including Mach IPC, POSIX semaphores and shared memory, and UNIX domain sockets.

    We should remove our PNSE.

  6. added this to the 9.0.0 milestone on Dec 19, 2023
  7. ghost removed
    untriaged
    on Dec 19, 2023
  8. modified the milestones: 9.0.0, 10.0.0 on Sep 10, 2024
  9. modified the milestones: 10.0.0, Future on Jul 18, 2025
  10. added
    good first issue
    on Jul 18, 2025
  11. aurimasc commented on Sep 2, 2026

    @aurimasc

    Modifying the following condition to enable iOS makes things work. iOS restricts paths to which domain sockets can be bind, but they do work.

    if (af == AddressFamily.Unix && (OperatingSystem.IsTvOS() || OperatingSystem.IsWasi() || (OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst())))

  12. shatanov commented on Sep 2, 2026

    @shatanov
    Contributor

    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.cs and add a
    regression test.

    Before I start implementing the fix, could you please confirm that this is the right direction: enable AddressFamily.Unix on iOS while keeping the explicit restrictions for tvOS and WASI?

  13. aurimasc commented on Sep 3, 2026

    @aurimasc

    Before I start implementing the fix, could you please confirm that this is the right direction: enable AddressFamily.Unix on iOS while keeping the explicit restrictions for tvOS and WASI?

    I haven't tried tvOS, but for iOS removing the guard allowed me to create and bind domain socket.

  14. akoeplinger commented on Sep 3, 2026

    @akoeplinger
    Member

    @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.

  15. added a commit that references this issue on Oct 3, 2026
    670efa0
  16. added
    in-pr
    on Oct 3, 2026
  17. added a commit that references this issue on Oct 19, 2026
    d8cc5a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Netgood first issuein-pros-ios

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions