Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSRunloop runUntilDate causes application crash

I have an application which runs for days and weeks on a Snow Leopard server. It uses -[NSRunLoop runUntilDate:] to "pause" for ten seconds, perform its task and then pause again. After running for over one hour, my app crashes with the following report:

Crash Report

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000013
Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Application Specific Information:
objc_msgSend() selector name: release

Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib                 0x00007fff84cfef0c objc_msgSend + 40
1   com.apple.CoreFoundation        0x00007fff84e363d1 __CFRunLoopDoSources0 + 1361
2   com.apple.CoreFoundation        0x00007fff84e345c9 __CFRunLoopRun + 873
3   com.apple.CoreFoundation        0x00007fff84e33d8f CFRunLoopRunSpecific + 575
4   com.apple.Foundation            0x00007fff83e73b74 -[NSRunLoop(NSRunLoop)  runMode:beforeDate:] + 270
5   com.apple.Foundation            0x00007fff83ebf19a -[NSRunLoop(NSRunLoop) runUntilDate:] + 78

At first glance I thought my NSRunLoop object is no longer valid and therefore the release message deep within CF causes a crash. However, I don't think that's the case as I obtain the reference to the currentRunLoop object in the line before.

The crash time varies between 1 and 1.5hrs but I can't get a handle on what's causing it. Any comments or opinions or debugging ideas would be greatly appreciated as I'm not sure what to do next.

EDIT: problem solve - please see my answer below

like image 505
helioz Avatar asked Dec 21 '22 07:12

helioz


1 Answers

Further tests have enabled me to answer my own question:

There is nothing wrong with the run loop. It is the run loop that handles that releases objects in the autorelease pool and that's why problems from any part of the code can show to be related to the Run Loop.

In my case, I had a object that wasn't cleaned up properly. Under normal circumstances this problem would have shown up during memory leak testing. However, this particular issue only arose on the actual client installation when an SMTP server returned an unexpected error message which caused an object to be "left over" and when the run loop eventually tried to clean it up, it came to a grinding halt.

The Short Answer

Crashes in the run loop can be caused by any object in the code. Try to re-create the problem scenario and test for memory leaks to find the offender.

like image 187
helioz Avatar answered Jan 10 '23 04:01

helioz