Connection error with SwiftNIO on macOS with SwiftUI and Xcode 12

Hello there,

I'm having getting this connection error, when trying to connect to a MySQL database using SwiftNIO (vapor/mysql-kit) on macOS with SwiftUI and Xcode 12

[si_destination_compare] socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL) failed: Operation not permitted
▿ connect(descriptor:addr:size:): Operation not permitted (errno: 1)
  - failureDescription: "connect(descriptor:addr:size:)"
  ▿ error: NIO.IOError.(unknown context at $10068db6c).Error.errno
    - errno: 1

Here is the code for connecting, pretty straight forward, but maybe I have something wrong:

        let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 2)
        self.eventLoopGroup = eventLoopGroup
        do {
            connection = try MySQLConnection.connect(to: .makeAddressResolvingHost("127.0.0.1", port: 3306),
                                                     username: "root",
                                                     database: "foo",
                                                     password: "test1234",
                                                     tlsConfiguration: .forClient(certificateVerification: .none),
                                                     logger: .init(label: "foo"),
                                                     on: eventLoopGroup.next()).wait()
        } catch {
            dump(error)
        }

This same code works fine when running from a swift executable from the command line, created with swift package init --type executable.

Wondering if there are any permissions needed for macOS apps on Xcode to open sockets, any help would be appreciated.

Thank you.

You need to make sure to enable "Outgoing Connections (Client)" in your macOS app's Signing & Capabilities settings.

1 Like

Thanks, that was it.

Terms of Service

Privacy Policy

Cookie Policy