Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KERN_INVALID_ADDRESS crash in [currentRunLoop runMode] #541

Closed
esilverberg opened this issue Apr 12, 2017 · 4 comments
Closed

KERN_INVALID_ADDRESS crash in [currentRunLoop runMode] #541

esilverberg opened this issue Apr 12, 2017 · 4 comments

Comments

@esilverberg
Copy link

I just ported my application to CocoaAsyncSocket, and now my number 1 crashing bug is one in CocoaAsyncSocket: GCDAsyncSocket-CFStream

Crashed: GCDAsyncSocket-CFStream
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000

Here is the thread

0
libsystem_pthread.dylib	
pthread_mutex_lock + 1330
1	CoreFoundation	
CFRunLoopSourceSignal + 64
2	Foundation	
performQueueDequeue + 468
3	Foundation	
__NSThreadPerformPerform + 136
4	CoreFoundation	
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
5	CoreFoundation	
__CFRunLoopDoSources0 + 388
6	CoreFoundation	
__CFRunLoopRun + 744
7	CoreFoundation	
CFRunLoopRunSpecific + 424
8
Foundation	
-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 304
9	CocoaAsyncSocket	
GCDAsyncSocket.m line 7533
+[GCDAsyncSocket cfstreamThread]
10
Foundation	
__NSThread__start__ + 996
11	libsystem_pthread.dylib	
_pthread_body + 240
12	libsystem_pthread.dylib	
_pthread_body + 282
13
libsystem_pthread.dylib	
thread_start + 4

I also can see that I have 2 other threads running the following code:

0
libsystem_kernel.dylib	
__psynch_cvwait + 8
1	libsystem_pthread.dylib	
_pthread_cond_wait + 640
2	Foundation	
-[NSCondition wait] + 240
3	Foundation	
-[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] + 764
4
Foundation	
-[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:] + 128
5	CocoaAsyncSocket	
GCDAsyncSocket.m line 7816
-[GCDAsyncSocket addStreamsToRunLoop]
6	CocoaAsyncSocket	
GCDAsyncSocket.m line 2916
__29-[GCDAsyncSocket didConnect:]_block_invoke.408
7	CocoaAsyncSocket	
GCDAsyncSocket.m line 2944
__29-[GCDAsyncSocket didConnect:]_block_invoke_2
8
libdispatch.dylib	
_dispatch_call_block_and_release + 24
9	libdispatch.dylib	
_dispatch_client_callout + 16
10	libdispatch.dylib	
_dispatch_queue_serial_drain + 928
11	libdispatch.dylib	
_dispatch_queue_invoke + 884
12	libdispatch.dylib	
_dispatch_queue_override_invoke + 344
13	libdispatch.dylib	
_dispatch_root_queue_drain + 540
14	libdispatch.dylib	
_dispatch_worker_thread3 + 124
15	libsystem_pthread.dylib	
_pthread_wqthread + 1096
16
libsystem_pthread.dylib	
start_wqthread + 4

and

0
libsystem_kernel.dylib	
__psynch_cvwait + 8
1	libsystem_pthread.dylib	
_pthread_cond_wait + 640
2	Foundation	
-[NSCondition wait] + 240
3	Foundation	
-[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] + 764
4
Foundation	
-[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:] + 128
5	CocoaAsyncSocket	
GCDAsyncSocket.m line 7816
-[GCDAsyncSocket addStreamsToRunLoop]
6	CocoaAsyncSocket	
GCDAsyncSocket.m line 2916
__29-[GCDAsyncSocket didConnect:]_block_invoke.408
7	CocoaAsyncSocket	
GCDAsyncSocket.m line 2944
__29-[GCDAsyncSocket didConnect:]_block_invoke_2
8
libdispatch.dylib	
_dispatch_call_block_and_release + 24
9	libdispatch.dylib	
_dispatch_client_callout + 16
10	libdispatch.dylib	
_dispatch_queue_serial_drain + 928
11	libdispatch.dylib	
_dispatch_queue_invoke + 884
12	libdispatch.dylib	
_dispatch_queue_override_invoke + 344
13	libdispatch.dylib	
_dispatch_root_queue_drain + 540
14	libdispatch.dylib	
_dispatch_worker_thread3 + 124
15	libsystem_pthread.dylib	
_pthread_wqthread + 1096
16
libsystem_pthread.dylib	
start_wqthread + 4

The crashing line is in this static method:

+ (void)cfstreamThread { @autoreleasepool
{
	[[NSThread currentThread] setName:GCDAsyncSocketThreadName];
	
	LogInfo(@"CFStreamThread: Started");
	
	// We can't run the run loop unless it has an associated input source or a timer.
	// So we'll just create a timer that will never fire - unless the server runs for decades.
	[NSTimer scheduledTimerWithTimeInterval:[[NSDate distantFuture] timeIntervalSinceNow]
	                                 target:self
	                               selector:@selector(ignore:)
	                               userInfo:nil
	                                repeats:YES];
	
	NSThread *currentThread = [NSThread currentThread];
	NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop];
	
	BOOL isCancelled = [currentThread isCancelled];
	
	while (!isCancelled && [currentRunLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]])
	{
		isCancelled = [currentThread isCancelled];
	}
	
	LogInfo(@"CFStreamThread: Stopped");
}}

and is specifically this line:

[currentRunLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]

Can anyone suggest why this method could be triggering an invalid nil address exception in CocoaAsyncSocket?

Thanks!

chrisballinger added a commit that referenced this issue May 8, 2017
Fix RunLoop / performSelector crash #541
@mttirnavali
Copy link

I'm also getting same crash, waiting for any fix/progress, thanks

@chrisballinger , does this commit fix the issue?

Crashed: GCDAsyncSocket-CFStream
0 libsystem_pthread.dylib 0x19027b2bc pthread_mutex_lock + 1330
1 CoreFoundation 0x191095a48 CFRunLoopSourceSignal + 64
2 Foundation 0x191bc5370 performQueueDequeue + 468
3 Foundation 0x191cae3f0 __NSThreadPerformPerform + 136
4 CoreFoundation 0x191169424 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 24
5 CoreFoundation 0x191168cfc __CFRunLoopDoSources0 + 388
6 CoreFoundation 0x1911669a0 __CFRunLoopRun + 744
7 CoreFoundation 0x191096d94 CFRunLoopRunSpecific + 424
8 Foundation 0x191bb0d64 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 304
9 CocoaAsyncSocket 0x10031cc6c +[GCDAsyncSocket cfstreamThread]
(GCDAsyncSocket.m:7529)
10 Foundation 0x191cae2c8 NSThread__start + 996
11 libsystem_pthread.dylib 0x19027d75c _pthread_body + 240
12 libsystem_pthread.dylib 0x19027d66c _pthread_body + 282
13 libsystem_pthread.dylib 0x19027ad84 thread_start + 4

@github-actions
Copy link

This issue has been marked as stale, it will be closed automatically if there is no further activity.

@HamzaYasin5
Copy link

i'm also getting the GCDAsyncSocket-CFStream (14): EXC_BAD_ACCESS (code=1, address=0x50) while asyncSocket deallocating.

Screen Shot 2022-09-01 at 6 30 51 AM

@lifrancis
Copy link

I have encountered the same problem. May I ask how this problem was resolved later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants