Crash in iOS: XPC API Misuse
Asked Answered
B

2

8

We have a crash in our iOS app reported by crashlytics:

Crashed: XPC API Misuse: Attempt to send a message expecting a reply to (com.apple.networking.connection.0x46bf35a0)

The stack trace is:

Thread : Crashed: XPC API Misuse: Attempt to send a message expecting a reply to  (com.apple.networking.connection.0x46bf35a0)
0  libxpc.dylib                   0x35cc534a _xpc_api_misuse + 41
1  libsystem_c.dylib              0x35ba49e5 __strlcpy_chk + 48
2  libxpc.dylib                   0x35cb5f75 _xpc_serializer_create + 158
3  libxpc.dylib                   0x35cb5ea1 xpc_connection_send_message + 60

It happened under iOS 9.0.2 on a iPhone 5. We are not able to reproduce the crash and we have no idea how to start debugging/fixing. It seems that we are not alone with this.

Maybe somebody here has any ideas.

Breathy answered 20/10, 2015 at 11:46 Comment(1)
Same crash for me out in the wild on iPhone 6 Plus with iOS 9.1.0.Xever
I
7

There are a lot of open bugs on this issue: rdar://21832853 is the original bug, along with rdar://22860899 and rdar://22874333, both of which are on OpenRadar.

I think that this is caused by some C-based networking code in SCNetworkReachability, and it is trying to talk to either the iOS VPN system—presumably to determine whether one is connected—or to the background daemon that is used for NSURLSession requests, but I'm not certain. Unfortunately, CFNetwork is not open source, and the libdispatch sources for 10.11 (as close to iOS 9 as you'll get) haven't been posted yet, so I can't even begin to guess what the networking code is doing wrong.

Either way, I don't think you're going to be able to work around it. With that said, assuming I'm right about the root cause, you might be able to reproduce it by running Network Link Conditioner and turning Airplane mode on and off repeatedly. Worth a try, anyway.

Internationalize answered 20/10, 2015 at 17:39 Comment(0)
S
0

I think it might be your code bug, I used to have the same problem every time when the application close, I have a destroy function which release the xpc connection as below:

void XpcComm::destory()
{
    std::lock_guard< std::mutex > lock( m_Lock );
    if ( m_xpcConn != nullptr )
    {
        xpc_connection_cancel( m_xpcConn );
        xpc_release( m_xpcConn );
    }
    m_xpcConn = nullptr;
}

I updated it to

void XpcComm::destory()
{
    std::lock_guard< std::mutex > lock( m_Lock );
    if ( m_xpcConn != nullptr )
    {
        xpc_connection_cancel( m_xpcConn );
        xpc_release( m_xpcConn );
        m_xpcConn = nullptr;
    }
    
}

and it fixed the xpc api misuse crash when close the application.

Sergias answered 27/2, 2022 at 1:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.