EXC_BREAKPOINT randomly using NSOutputStream

I am writing an application that uses NSOutputStream. I start the connection like this:

delegate = self;
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;

CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)url,port, &readStream, &writeStream);
CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);

inputStream = (__bridge_transfer NSInputStream *)readStream;
outputStream = (__bridge_transfer NSOutputStream *)writeStream;

[inputStream setDelegate:delegate];
[outputStream setDelegate:delegate];

loop = [NSRunLoop currentRunLoop];
[inputStream scheduleInRunLoop:loop forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:loop forMode:NSDefaultRunLoopMode];

[inputStream setProperty:NSStreamSocketSecurityLevelTLSv1 forKey:NSStreamSocketSecurityLevelKey];
[outputStream setProperty:NSStreamSocketSecurityLevelTLSv1 forKey:NSStreamSocketSecurityLevelKey];



[inputStream setProperty:NSStreamSocketSecurityLevelNegotiatedSSL
                  forKey:NSStreamSocketSecurityLevelKey];
[outputStream setProperty:NSStreamSocketSecurityLevelNegotiatedSSL
                   forKey:NSStreamSocketSecurityLevelKey];

NSDictionary *settings = [[NSDictionary alloc] initWithObjectsAndKeys:
                          [NSNumber numberWithBool:YES], kCFStreamSSLAllowsExpiredCertificates,
                          [NSNumber numberWithBool:YES], kCFStreamSSLAllowsAnyRoot,
                          [NSNumber numberWithBool:NO], kCFStreamSSLValidatesCertificateChain,
                          kCFNull,kCFStreamSSLPeerName,
                          nil];

CFReadStreamSetProperty((CFReadStreamRef)inputStream, kCFStreamPropertySSLSettings, (CFTypeRef)settings);
CFWriteStreamSetProperty((CFWriteStreamRef)outputStream, kCFStreamPropertySSLSettings, (CFTypeRef)settings);

[outputStream open];
[inputStream open];

[self sendVersionOrWait];
[loop run];

      

and then some of the actions depend on the NSStreamDelegate methods. Closing a connector is done by:

 [inputStream close];
[outputStream close];
[inputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream setDelegate:nil];
[outputStream setDelegate:nil];

inputStream = nil;
outputStream = nil;

      

Sometimes (accidentally) I get EXC_BREAKPOINT and the application crashes. This is part of the crash log:

Exception type: EXC_BREAKPOINT (SIGTRAP) Exception codes: 0x0000000000000001, 0x000000000000defe Subject trigger: 5

Topic name 5: Send Queue: com.apple.root.default-qos

Topic 5 Failure:

0 CoreFoundation 0x22767e22 CFHash + 130

1 CoreFoundation 0x22768d70 CFBasicHashGetCountOfKey + 1152

2 CoreFoundation 0x227688aa CFSetContainsValue + 98

3 CoreFoundation 0x2279ca5a CFRunLoopRemoveSource + 226

4 CFNetwork 0x22343eca SocketStream :: write (__ CFWriteStream *, unsigned char const *, long, CFStreamError *) + 426

5 CFNetwork 0x223480c2 WriteStreamCallbacks :: _ write (__ CFWriteStream *, unsigned char const *, long, CFStreamError *, void *) + 34

6 CoreFoundation 0x2278d7ec CFWriteStreamWrite + 356

7 App 0x000a0190 - [AppMenuViewController sendVersion] (AppMenuViewController.m: 763)

8 App 0x000a0c68 - [AppMenuViewController sendVersionOrWait] (AppMenuViewController.m: 832)

9 Foundation 0x235655e4 __NSFireDelayedPerform + 464

10 CoreFoundation 0x22828734 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 12

11 CoreFoundation 0x228282b4 __CFRunLoopDoTimer + 652

12 CoreFoundation 0x2282651e __CFRunLoopRun + 1414

13 CoreFoundation 0x22773dac CFRunLoopRunSpecific + 472

14 CoreFoundation 0x22773bbe CFRunLoopRunInMode + 102

15 Foundation 0x234ab16c - [NSRunLoop (NSRunLoop) runMode: beforeDate:] + 260

16 Foundation 0x234f95e0 - [NSRunLoop (NSRunLoop) run] + 76

17 App 0x0009feaa - [AppMenuViewController initConnection: withPort:] (AppMenuViewController.m: 749)

18 Application 0x000a1642 - [AppMenuViewController stream: handleEvent:] (AppMenuViewController.m: 952)

19 CoreFoundation 0x227d9b94 _signalEventSync + 144

20 CoreFoundation 0x227e3ef2 _cfstream_solo_signalEventSync + 198

21 CoreFoundation 0x227d981e _CFStreamSignalEvent + 322

22 CFNetwork 0x222b7bd4 SocketStream :: dispatchSignalFromSocketCallbackUnlocked (SocketStreamSignalHolder *) +36

23 CFNetwork 0x222b78be SocketStream :: socketCallback (__ CFSocket *, unsigned long, __CFData const *, void const *) + 146

24 CFNetwork 0x222b77f2 SocketStream :: _ SocketCallBack_stream (__ CFSocket *, unsigned long, __CFData const *, void const *, void *) + 54

25 CoreFoundation 0x2282b0bc __CFSocketPerformV0 + 552

26 CoreFoundation 0x22828804 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 12

27 CoreFoundation 0x22827c16 __CFRunLoopDoSources0 + 218

28 CoreFoundation 0x22826294 __CFRunLoopRun + 764

29 CoreFoundation 0x22773dac CFRunLoopRunSpecific + 472

30 CoreFoundation 0x22773bbe CFRunLoopRunInMode + 102

31 Foundation 0x234ab16c - [NSRunLoop (NSRunLoop) runMode: beforeDate:] + 260

32 Foundation 0x234f95e0 - [NSRunLoop (NSRunLoop) run] + 76

33 App 0x0009feaa - [AppMenuViewController initConnection: withPort:] (AppMenuViewController.m: 749)

34 Application 0x0009b664 __58- [AppMenuViewController alertView: clickedButtonAtIndex:] _ block_invoke (AppMenuViewController.m: 385)

35 libdispatch.dylib 0x30521610 _dispatch_call_block_and_release + 8

36 libdispatch.dylib 0x3052d350 _dispatch_root_queue_drain + 816

37 libdispatch.dylib 0x3052e27a _dispatch_worker_thread3 + 102

38 libsystem_pthread.dylib 0x3069ee22 _pthread_wqthread + 666

39 libsystem_pthread.dylib 0x3069eb74 start_wqthread + 4

I suppose this could be caused by network problems because it appears when my WIFI router has no internet connection. But I'm not sure and I don't know how to remove this error. Please, help:)

+3


source to share


1 answer


I'm guessing it has to do with streaming. Try submitting to the main thread to make sure it's all done on the main thread, and see if this is causing an exciting issue. If so, you know where to look ....



0


source







All Articles