XPC connection interrupted

Hi,


I am getting this error, "XPC connection interrupted" and caused my app to crash.


Any idea what is this?


I had tried to simulate but can't seems to get it to "crash". It happened at random moment while in app without any pattern (be it trying to call server API or processing json, etc).


The error message that I'm getting is "XPC connection interrupted" and nothing else. I have no idea what ios version that causes it to crash.


Appreciate if anyone can help.


Thanks.

Replies

An XPC connection is interrupted when the remote process terminates. This can happen for abnormal reasons (for example, the remote process crashing) and for normal reasons (the system terminating the remote process to recover memory). If you’re using XPC directly, which is typically only done on macOS [1], you must be prepared to handle either eventuality.

However, it seems that you’re on iOS, in which case you rarely use XPC directly but rather use it via some framework, and it’s the framework’s responsibility to handle interruptions. So the actual problem here is a bit of a mystery.

You wrote:

I am getting this error, "XPC connection interrupted" and caused my app to crash.

Please post the crash report you got.

Share and Enjoy

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

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

[1] XPC is available on iOS starting with iOS 11, but the only supported use case is custom calls to file providers, which is a pretty obscure part of the system. If you’re using XPC directly, please do let me know.

hi ,

now i have a trouble with xpc.

I need to load a dynamic library use xpc..this library need to display UI.Then console catch error :


*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:


'NSWindow drag regions should only be invalidated on the Main Thread!'

*** First throw call stack:

(

0 CoreFoundation 0x00007fff49eceecd __exceptionPreprocess + 256

1 libobjc.A.dylib 0x00007fff75f96720 objc_exception_throw + 48

2 CoreFoundation 0x00007fff49ee895d -[NSException raise] + 9

3 AppKit 0x00007fff473e9c8e -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 324

4 AppKit 0x00007fff473e707c -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1488

5 AppKit 0x00007fff473e6aa6 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 45

6 AppKit 0x00007fff473e4fb7 -[NSWindowTemplate nibInstantiate] + 495

7 AppKit 0x00007fff4736004e -[N<…>


how can i run it ? thanks ..

'NSWindow drag regions should only be invalidated on the Main Thread!'

Something in your process is calling AppKit from a secondary thread. It’s hard to say what because you’ve posted a truncated backtrace. What does the full backtrace look like?

Share and Enjoy

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

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

That is all backtrace..

After that ,there is have a log .


I have been try it with dispatch_async in main quque.


dispatch_async(dispatch_get_main_queue(), ^{

testView *tv = [[testView alloc] initWithWindowNibName:@"testView"];

[tv showSelfWindow];

});



-(void)showSelfWindow

{

[NSApp activateIgnoringOtherApps:YES];

[[self window] makeKeyAndOrderFront:self];

[[self window] setLevel:NSFloatingWindowLevel];

[NSApp beginModalSessionForWindow:[self window]];

}

Then,this xpc process is crashed. such as:


Process: xpcHelp [24703]

Path: /Users/USER/Library/Developer/Xcode/DerivedData/FeiTianMgr-dksrvbbveekoewdqoukdcwspttaz/Build/Products/Debug/FeiTianMgr.app/Contents/PlugIns/BrowserExt.appex/Contents/XPCServices/xpcHelp.xpc/Contents/MacOS/xpcHelp

Identifier: com.ftsafe.xpcHelp

Version: 1.0 (1)

Code Type: X86-64 (Native)

Parent Process: ??? [24682]

Responsible: BrowserExt [24688]

User ID: 501



Date/Time: 2019-02-18 11:50:05.637 +0800

OS Version: Mac OS X 10.14.3 (18D32a)

Report Version: 12

Bridge OS Version: 3.3 (16P53129a)

Anonymous UUID: 7E1DE390-4665-9E9B-5FE8-F973A45D07C5



Sleep/Wake UUID: 9424F2D7-4B0C-41F7-9917-14B1C774054C



Time Awake Since Boot: 230000 seconds

Time Since Wake: 69000 seconds



System Integrity Protection: enabled



Crashed Thread: 4 Dispatch queue: com.apple.main-thread



Exception Type: EXC_CRASH (SIGABRT)

Exception Codes: 0x0000000000000000, 0x0000000000000000

Exception Note: EXC_CORPSE_NOTIFY



External Modification Warnings:

Debugger attached to process.



Application Specific Information:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'

abort() called

terminating with uncaught exception of type NSException



Application Specific Backtrace 1:

0 CoreFoundation 0x00007fff49eceecd __exceptionPreprocess + 256

1 libobjc.A.dylib 0x00007fff75f96720 objc_exception_throw + 48

2 CoreFoundation 0x00007fff49ee895d -[NSException raise] + 9

3 AppKit 0x00007fff473e9c8e -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 324

4 AppKit 0x00007fff473e707c -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1488

5 AppKit 0x00007fff473e6aa6 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 45

6 AppKit 0x00007fff473e4fb7 -[NSWindowTemplate nibInstantiate] + 495

7 AppKit 0x00007fff4736004e -[NSIBObjectData instantiateObject:] + 267

8 AppKit 0x00007fff4735f3bc -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 579

9 AppKit 0x00007fff4735d5e9 loadNib + 401

10 AppKit 0x00007fff4735cab1 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 696

11 AppKit 0x00007fff474e90d2 +[NSBundle(NSNibLoadingInternal) _loadNibFile:externalNameTable:options:withZone:] + 156

12 AppKit 0x00007fff474e8e8f -[NSWindowController loadWindow] + 322

13 AppKit 0x00007fff4744b618 -[NSWindowController window] + 84

14 xpcHelp 0x00000001099e71da -[testView showSelfWindow] + 58

15 xpcHelp 0x0000000109a3a747 __48-[xpcHelp sendToXpcWith:withUserInfo:withReply:]_block_invoke + 87

16 libdispatch.dylib 0x00007fff77015d53 _dispatch_call_block_and_release + 12

17 libdispatch.dylib 0x00007fff77016dcf _dispatch_client_callout + 8

18 libdispatch.dylib 0x00007fff7701d124 _dispatch_lane_serial_drain + 618

19 libdispatch.dylib 0x00007fff7701dc0c _dispatch_lane_invoke + 436

20 libdispatch.dylib 0x00007fff77024d26 _dispatch_root_queue_drain + 325

21 libdispatch.dylib 0x00007fff770254bd _dispatch_worker_thread2 + 90

22 libsystem_pthread.dylib 0x00007fff772576dd _pthread_wqthread + 619

23 libsystem_pthread.dylib 0x00007fff77257405 start_wqthread + 13



Thread 0:

0 libsystem_kernel.dylib 0x00007fff771a207a __semwait_signal_nocancel + 10

1 libsystem_c.dylib 0x00007fff770b7962 nanosleep$NOCANCEL + 188

2 libsystem_c.dylib 0x00007fff770ddf2a sleep$NOCANCEL + 41

3 libdispatch.dylib 0x00007fff77026838 _dispatch_queue_cleanup2 + 112

4 libsystem_pthread.dylib 0x00007fff772586c2 _pthread_tsd_cleanup + 550

5 libsystem_pthread.dylib 0x00007fff7725b679 _pthread_exit + 70

6 libsystem_pthread.dylib 0x00007fff77258473 pthread_exit + 30

7 libdispatch.dylib 0x00007fff77022291 dispatch_main + 110

8 libxpc.dylib 0x00007fff7729ceda _xpc_objc_main + 583

9 libxpc.dylib 0x00007fff7729c9bd xpc_main + 433

10 com.apple.Foundation 0x00007fff4c189ce4 -[NSXPCListener resume] + 162

11 com.ftsafe.xpcHelp 0x00000001099e73de main + 142 (main.m:47)

12 libdyld.dylib 0x00007fff77064ed9 start + 1



Thread 1:: Dispatch queue: com.apple.NSXPCConnection.user.24688

0 libsystem_kernel.dylib 0x00007fff771a1eae __semwait_signal + 10

1 libsystem_c.dylib 0x00007fff7712c830 nanosleep + 199

2 libsystem_c.dylib 0x00007fff7712c692 sleep + 41

3 com.ftsafe.xpcHelp 0x0000000109a3a603 -[xpcHelp sendToXpcWith:withUserInfo:withReply:] + 371 (xpcHelp.mm:25)

4 com.apple.Foundation 0x00007fff4c1acd93 __NSXPCCONNECTION_IS_CALLING_OUT_TO_EXPORTED_OBJECT_S3__ + 12

5 com.apple.Foundation 0x00007fff4c18bb38 -[NSXPCConnection _decodeAndInvokeMessageWithEvent:flags:] + 2609

6 com.apple.Foundation 0x00007fff4c18ae9c message_handler + 227

7 libxpc.dylib 0x00007fff77298a28 _xpc_connection_call_event_handler + 56

8 libxpc.dylib 0x00007fff772969be _xpc_connection_mach_event + 933

9 libdispatch.dylib 0x00007fff77016e6f _dispatch_client_callout4 + 9

10 libdispatch.dylib 0x00007fff7702bb0f _dispatch_mach_msg_invoke + 449

11 libdispatch.dylib 0x00007fff7701cfc9 _dispatch_lane_serial_drain + 271

12 libdispatch.dylib 0x00007fff7702c639 _dispatch_mach_invoke + 485

13 libdispatch.dylib 0x00007fff7701cfc9 _dispatch_lane_serial_drain + 271

14 libdispatch.dylib 0x00007fff7701dc0c _dispatch_lane_invoke + 436

15 libdispatch.dylib 0x00007fff77026090 _dispatch_workloop_worker_thread + 603

16 libsystem_pthread.dylib 0x00007fff7725760b _pthread_wqthread + 409

17 libsystem_pthread.dylib 0x00007fff77257405 start_wqthread + 13



Thread 2:: Dispatch queue: com.apple.root.default-qos.overcommit

0 libsystem_kernel.dylib 0x00007fff771a20a2 __sigsuspend_nocancel + 10

1 libdispatch.dylib 0x00007fff770268b5 _dispatch_sigsuspend + 21

2 libdispatch.dylib 0x00007fff770268a0 _dispatch_sig_thread + 53



Thread 3:

0 libsystem_pthread.dylib 0x00007fff772573f8 start_wqthread + 0

1 ??? 0xffffffffffffff00 0 + 18446744073709551360



Thread 4 Crashed:: Dispatch queue: com.apple.main-thread

0 libsystem_kernel.dylib 0x00007fff771a423e __pthread_kill + 10

1 libsystem_pthread.dylib 0x00007fff7725ac1c pthread_kill + 285

2 libsystem_c.dylib 0x00007fff7710d1c9 abort + 127

3 libc++abi.dylib 0x00007fff7478d231 abort_message + 231

4 libc++abi.dylib 0x00007fff7478d3cd default_terminate_handler() + 265

5 libobjc.A.dylib 0x00007fff75f98c87 _objc_terminate() + 97

6 libc++abi.dylib 0x00007fff74798dfe std::__terminate(void (*)()) + 8

7 libc++abi.dylib 0x00007fff74798e73 std::terminate() + 51

8 libdispatch.dylib 0x00007fff77016de3 _dispatch_client_callout + 28

9 libdispatch.dylib 0x00007fff7701d124 _dispatch_lane_serial_drain + 618

10 libdispatch.dylib 0x00007fff7701dc0c _dispatch_lane_invoke + 436

11 libdispatch.dylib 0x00007fff77024d26 _dispatch_root_queue_drain + 325

12 libdispatch.dylib 0x00007fff770254bd _dispatch_worker_thread2 + 90

13 libsystem_pthread.dylib 0x00007fff772576dd _pthread_wqthread + 619

14 libsystem_pthread.dylib 0x00007fff77257405 start_wqthread + 13

Oh, you’re running this within an XPC Service! That’s a critical tibit.

Consider this snippet from your crash report:

Crashed Thread: 4  Dispatch queue: com.apple.main-thread

What’s weird about this is that the main queue is being run by thread 4. In normal application code, the main queue is always run by the main thread, that is, thread 0.

The reason this is happening is that you’re inside an XPC Service. By default an XPC Service’s main thread calls

dispatch_main
(see its man page), and that triggers a very nice but very unusual behaviour: It terminates the main thread but leaves the process running!

This is nice because it saves resources. If the XPC Service is dormant, there’s no point leaving a thread lying around doing nothing.

It’s weird because of its impact on main queue operations. When you dispatch something to the main queue, you expect it to run on the main thread, but here there’s no main thread to run the main queue. Instead, Dispatch temporarily assigns some other worker thread to run your main queue work. Main queue work is still serialised, it’s just not running on the main thread.

The problem comes when you call AppKit, which has all sorts of ‘must run on the main thread’ checks. In situation like this these checks will fail, throwing an exception that terminates your XPC Service process.

Fortunately there’s an easy fix: Configure your XPC Service to not call

dispatch_main
. You do this by setting the
RunLoopType
property to
NSRunLoop
. See the
xpcservice.plist
man page for details.

Share and Enjoy

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

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