IOS-Exception Type: 00000020: What is the watchdog mechanism, ios-00000020
1. preface a Crash we encountered after the project Crash a few days ago. After visiting many forums, the blog did not find a satisfactory reply.IOS watchdog mechanismWith a basic understanding, there are a lot of strange Crash may be shared today because of the iOS watchdog mechanism. I hope it will help later. Let's take a look at the Crash Report 2. iOS App Crash Report analysis
Date/Time: 2016-01-25 12:19:48.746 +0100Launch Time: 2016-01-22 15:12:37.422 +0100OS Version: iOS 8.4 (12H143)Report Version: 105Exception Type: 00000020Exception Codes: 0x000000008badf00dHighlighted Thread: 0Application Specific Information:<BKNewProcess: 0x12cd26cf0; com.scasy.Dinnn; pid: 248; hostpid: -1> has active assertions beyond permitted time:{(<BKProcessAssertion: 0x12ce1b400> id: 248-C89C6FAD-B496-46ED-B59A-20D976A02D10 name: Called by ExternalAccessory, from <redacted> process: <BKNewProcess: 0x12cd26cf0; com.scasy.Dinnn; pid: 248; hostpid: -1> permittedBackgroundDuration: 180.000000 reason: finishTask owner pid:248 preventSuspend preventIdleSleep preventSuspendOnSleep)}Elapsed total CPU time (seconds): 0.130 (user 0.130, system 0.000), 1% CPUElapsed application CPU time (seconds): 0.044, 0% CPUThread 0 name: Dispatch queue: com.apple.main-threadThread 0:0 libsystem_kernel.dylib 0x342ec474 mach_msg_trap + 201 libsystem_kernel.dylib 0x342ec269 mach_msg + 372 CoreFoundation 0x25a1256f __CFRunLoopServiceMachPort + 1433 CoreFoundation 0x25a10b15 __CFRunLoopRun + 10134 CoreFoundation 0x2595d1fd CFRunLoopRunSpecific + 4735 CoreFoundation 0x2595d00f CFRunLoopRunInMode + 1036 Foundation 0x266c7139 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 2617 Foundation 0x26715221 -[NSRunLoop(NSRunLoop) run] + 778 Dinnn 0x0014af59 -[ConnectServerViewController updateInitDinnnThread:] (ConnectServerViewController.m:425)9 Foundation 0x2678c5cb __NSThreadPerformPerform + 38310 CoreFoundation 0x25a12fad __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 1311 CoreFoundation 0x25a123bb __CFRunLoopDoSources0 + 21512 CoreFoundation 0x25a10a21 __CFRunLoopRun + 76913 CoreFoundation 0x2595d1fd CFRunLoopRunSpecific + 47314 CoreFoundation 0x2595d00f CFRunLoopRunInMode + 10315 GraphicsServices 0x2d2d81fd GSEventRunModal + 13316 UIKit 0x29129a05 UIApplicationMain + 143717 Dinnn 0x00088c47 main (main.m:17)18 libdyld.dylib 0x34235aad start + 1
First, locate the exception type:
Exception Type: 00000020In short, Exception Type: 00000020 means that the Asynchronous Network you are working on is in the main thread. When the connection or running is slow, the application can terminate iOS. This will happen randomly. The most common cause is that the watchdog timeout and crash of an application in a network is the main thread for synchronizing the network.
There are three factors:1. synchronous network-this is where your network requests and blocking wait for response. 2. The main thread-synchronization network is generally not ideal, but it will cause specific problems, if you do so on the main thread. Remember that the main thread is responsible for running the user interface. If you block any significant time of the main thread, the user interface becomes dull. 3. Long-term timeout-if the network disappears (for example, the user enters the tunnel on the train), no pending network requests will fail until the timeout expires. Most network timeouts are calculated in minutes, that is, blocking synchronous network requests can maintain the response time on the user interface at the same time in the main thread. It is a bad idea to try to avoid this problem by reducing network timeout. In some cases, it can take many seconds for network requests to succeed. If you are always ahead of time, then you will never make any progress. Watchdog-to maintain the response of the user interface, the iOS system includes a watchdog mechanism. If your application fails to respond to certain user interface events (START, pause, resume, and stop), the watchdog will kill your application and generate a report of a watchdog timeout crash. One tricky aspect of this problem is that it is highly dependent on the network environment. If you always test your application in your office, the network connection is good and you will never see this type of crash. However, once you start to deploy your application, end users who will run in various network environments will crash like this.
Conclusion,If you perform synchronous online call on the main thread, your application will crash when the watchdog times out when it is deployed to a wide environment. From the top 6 and 7 in the Crash report, we can see the specific cause. We can see the specific location in 8 rows. Details: About
-(BOOL) runMode :( NSString *) mode beforeDate :( NSDate *) date;The method specifies the runloop mode to process the input source. The first input source or date ends and exits. Pause the current processing process and process other input sources. When date is set to [NSDate distantFuture] (in the future, it will not be reached ),
Therefore, unless processing other input sources ends, the current processing process of the processing pause will never exit.
The report clearly tells us that this is blocked, indicating that the Run loop is currently on the main thread, so our APP is finally killed by the iOS watchdog mechanism.Conclusion: Once you confirm that this problem is related to your network code, there is a common solution:
Asynchronous Network-the best solution to this problem is to run your network code asynchronously.Asynchronous Network code has many advantages, at least it allows you to access the network securely without worrying about threads. It is more difficult to run your network code asynchronously on the secondary thread synchronization network (maybe you have a large portable code library, assuming that the synchronization network works ), you can avoid the watchdog by running your synchronization code on the auxiliary thread. How to run the network code asynchronously, including multithreading. You can view the relevant information in the Apple documentation. If you have any questions about the iOS door-watching mechanism, please leave a message. Author: Clear Saup
Source: http://www.cnblogs.com/qingche/
The copyright of this article is shared by the author and the blog. You are welcome to repost it, but you must keep this statement and provide a connection to the original article on the article page.