neagent fails to start the plugin [NSCocoaErrorDomain Code=4097]

Hi, We have developed a per-app VPN (and containing app) on iOS 9.x/iOS 10.x based on Network Extension NEAppProxyProvider. VPN configurations are generated and distributed to devices. Sometimes the plugin doesn't lauch and fails with below error in device logs. This is an intermittent issue but once the device goes into this state it never comes back unless restarted or enrolled into another environment. It's not clear from the device log nda errorcode 4097 is pretty generic which just means

The operation couldn’t be completed
.

It looks like a IPC failure but reason is unknown. Any insight into this error will help.


Jun 6 12:55:10 test-iPhone pkd[90] <Info>: match returned 1 plug-ins
Jun 6 12:55:10 test-iPhone neagent(Foundation)[2409] <Notice>: calling plugIn beginUsing:
Jun 6 12:55:10 test-iPhone pkd[90] <Info>: assigning plug-in <private>(<private>) D0FC15A1-A6B9-49CC-B4C7-2689CA489B72 to plugin sandbox
Jun 6 12:55:10 test-iPhone pkd[90] <Notice>: allowing host 2409 <private> to use plug-in <private>(<private>) uuid=D0FC15A1-A6B9-49CC-B4C7-2689CA489B72 at <private>
Jun 6 12:55:10 test-iPhone neagent(PlugInKit)[2409] <Info>: preparing plug-in <private>(<private>)
Jun 6 12:55:10 test-iPhone neagent(PlugInKit)[2409] <Notice>: connection to plug-in <private>(D0FC15A1-A6B9-49CC-B4C7-2689CA489B72) lost
Jun 6 12:55:10 test-iPhone neagent(PlugInKit)[2409] <Error>: Hub connection error Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.companyname.AppProxy" UserInfo={NSDebugDescription=connection to service named com.companyname.AppProxy}
Jun 6 12:55:10 test-iPhone neagent(PlugInKit)[2409] <Info>: beginUsing of D0FC15A1-A6B9-49CC-B4C7-2689CA489B72 concludes with error=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.companyname.AppProxy" UserInfo={NSDebugDescription=connection to service named com.companyname.AppProxy}
Jun 6 12:55:10 test-iPhone neagent(Foundation)[2409] <Notice>: PlugInKit error in beginUsing:
Jun 6 12:55:10 test-iPhone neagent(Foundation)[2409] <Notice>: killing invalid plugIn
Jun 6 12:55:10 test-iPhone neagent(NetworkExtension)[2409] <Error>: Failed to start extension com.companyname.AppProxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.companyname.AppProxy" UserInfo={NSDebugDescription=connection to service named com.companyname.AppProxy}
Jun 6 12:55:10 test-iPhone neagent(NetworkExtension)[2409] <Info>: Dispose complete
Jun 6 12:55:10 test-iPhone neagent(NetworkExtension)[2409] <Info>: XPC connection went away (Connection invalid)
Jun 6 12:55:10 test-iPhone MITunnel(libsystem_trace.dylib)[2968] <Notice>: subsystem: com.apple.networkextension, category: , enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0
Jun 6 12:55:10 test-iPhone nesessionmanager(NetworkExtension)[2406] <Info>: NESMFlowDivertSession[iOS VPN2:4C1F45FF-C6E1-4C31-9778-BFD64D7FF4E4] in state NESMVPNSessionStateIdle: plugin NEFlowDivertPlugin(com.companyname.AppProxy[2409]) started with PID 0
Jun 6 12:55:10 test-iPhone nesessionmanager(NetworkExtension)[2406] <Info>: NESMFlowDivertSession[iOS VPN2:4C1F45FF-C6E1-4C31-9778-BFD64D7FF4E4] in state NESMVPNSessionStateIdle: sent establish IPC reply
Jun 6 12:55:10 test-iPhone nesessionmanager(NetworkExtension)[2406] <Info>: NESMFlowDivertSession[iOS VPN2:4C1F45FF-C6E1-4C31-9778-BFD64D7FF4E4] in state NESMVPNSessionStateIdle: plugin NEFlowDivertPlugin(com.companyname.AppProxy[2409]) did detach from IPC
Jun 6 12:55:10 test-iPhone nesessionmanager(NetworkExtension)[2406] <Info>: com.companyname.AppProxy[2409]: disposing
Jun 6 12:55:10 test-iPhone nesessionmanager(NetworkExtension)[2406] <Info>: com.companyname.AppProxy[2409]: disposed with error: 0
Jun 6 12:55:10 test-iPhone nesessionmanager(NetworkExtension)[2406] <Info>: com.companyname.AppProxy[2409]: exited
Jun 6 12:55:10 test-iPhone nesessionmanager(NetworkExtension)[2406] <Info>: NESMFlowDivertSession[iOS VPN2:4C1F45FF-C6E1-4C31-9778-BFD64D7FF4E4] in state NESMVPNSessionStateIdle: plugin NEFlowDivertPlugin(com.companyname.AppProxy[inactive]) dispose complete
Jun 6 12:55:10 test-iPhone neagent(libxpc.dylib)[2409] <Notice>: Could not signal service com.companyname.AppProxy: 113: Could not find specified service
Jun 6 12:55:10 test-iPhone neagent(Foundation)[2409] <Notice>: completed calling plugIn beginUsing: for pid: 0

Error 4097 is a very generic XPC error code. If you look in the macOS SDK you’ll find it declared as

NSXPCConnectionInterrupted
. This telly you that the plug-in was unable to start, but offers no input as to why that might be the case.

Was this log taken with the VPN debugging profile (see Bug Reporting > Profiles and Logs) installed? If not, I recommend that you install that and see if it produces any more details information.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Was this log taken with the VPN debugging profile (see Bug Reporting > Profiles and Logs) installed?

No, it was not. The issue went away after we entrolled the device to some other setup so we lost the opportunity to do it again.

I'll keep profiling in mind next time it happens.

Thanks!

neagent fails to start the plugin [NSCocoaErrorDomain Code=4097]
 
 
Q