6

我在使用 SocketRocket 时遇到 iOS EXC_BAD_ACCESS 错误,我想知道我可以做些什么来进一步调试问题以确定问题是在我这边还是在 SocketRocket 那边。

我得到的堆栈跟踪是:

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x2000000c
raw
0    libobjc.A.dylib     objc_msgSend + 5
1    OMlearnings         SRWebSocket.m line 692    __30-[SRWebSocket _failWithError:]_block_invoke_2
2    libdispatch.dylib   _dispatch_call_block_and_release + 10
10   UIKit               UIApplicationMain + 1136
11   OMlearnings         main.m line 16    main

或者有时

Crashed: NSOperationQueue Serial Queue
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0xc
raw
0    libobjc.A.dylib     objc_msgSend + 5
1    OMlearnings         SRWebSocket.m line 613    -[SRWebSocket scheduleInRunLoop:forMode:]
2    OMlearnings         SRWebSocket.m line 600    -[SRWebSocket _connect]
3    OMlearnings         OMSRealTimeTeamDashboard.m line 157    -[OMSRealTimeTeamDashboard sendMessage:]
4    OMlearnings         OMSRealTimeTeamDashboard.m line 171    -[OMSRealTimeTeamDashboard eventReceived:]
5    CoreFoundation      __invoking___ + 68
6    CoreFoundation      -[NSInvocation invoke] + 282
7    Foundation          -[NSInvocationOperation main] + 112
8    Foundation          -[__NSOperationInternal _start:] + 770
14   libsystem_pthread.dylib _pthread_wqthread + 298

我的代码库很简单,基本上订阅事件,并在队列中执行socketrocket sendMessage(处理并发)

[signalServices subscribe:my-event toBlock:^(NSNotification * notification) {
    [this.queue addOperation:[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(eventReceived:) object:notification]];
}];

- (void)eventReceived: (NSNotification *)notification {
    // ...
    [socket send:[NSString stringWithFormat:@"%i,1,%@", currentUserId.intValue, [NSNumber numberWithInt: rate.value]]];
}

我读过有人使用 NSZombies 来调试问题,但我的问题很少发生,所以我可能会在问题变得可见之前耗尽内存。它在 99% 的时间里都能正常工作。

有什么关于 iOS 可能会随机崩溃使用套接字等的应用程序的信息吗?例如,我们启用了后台提取,这可能是一些随机崩溃的原因吗?

谢谢 !

4

1 回答 1

4

在堆栈跟踪中,

0    libobjc.A.dylib     objc_msgSend + 5
1    OMlearnings         SRWebSocket.m line 692    __30-[SRWebSocket _failWithError:]_block_invoke_2

EXC_BAD_ACCESS发生在这一行,https://github.com/square/SocketRocket/blob/master/SocketRocket/SRWebSocket.m#L692

[self.delegate webSocket:self didFailWithError:error];

根据文档,https://github.com/square/SocketRocket

SRWebSocket
(unlike NSURLConnection, SRWebSocket won't retain the delegate)

@property (nonatomic, assign) id <SRWebSocketDelegate> delegate;

SRWebSocket 对象没有保留委托属性,因此,如果您不保留委托对象,它将与悬空指针一起崩溃。您如何对委托对象进行强引用?

于 2013-12-18T23:48:48.017 回答