App often crashes at INVALID_STATE_ERR
1 CoreFoundation __exceptionPreprocess + 126
2 libobjc.A.dylib objc_exception_throw + 34
3 PeerIM -[ComGoodowRealtimeChannelImplWebSocketBus sendWithComGoodowRealtimeJsonJsonObject:] (WebSocketBus.m:130)
4 PeerIM -[ComGoodowRealtimeChannelImplReconnectBus sendWithComGoodowRealtimeJsonJsonObject:] (ReconnectBus.m:65)
5 PeerIM -[ComGoodowRealtimeChannelImplWebSocketBus sendPing] (WebSocketBus.m:147)
I notice it throws an exception here:
WebSocketBus.m:
- (void)sendWithComGoodowRealtimeJsonJsonObject:(id<ComGoodowRealtimeJsonJsonObject>)msg {
if ([self getReadyState] != ComGoodowRealtimeChannelStateEnum_get_OPEN()) {
@throw [[JavaLangIllegalStateException alloc] initWithNSString:@"INVALID_STATE_ERR"];
}
[((id<ComGoodowRealtimeCoreWebSocket>) nil_chk(webSocket_)) sendWithNSString:[((id<ComGoodowRealtimeJsonJsonObject>) nil_chk(msg)) toJsonString]];
}
Why? Also, this exception happens when the app goes to background for a while and comes back to foreground.
Try to debug with ReconnectBus The java version: ReconnectBus.send
Maybe use Xcode or Eclipse's Exception Breakpoint, then inspect which data is sending.
Do you think it is possible that ReconnectBus send sendPing -> ReconnectBus sendWithComGoodowRealtimeJsonJsonObject -> app goes to background -> app goes to foreground WebsocketBus sendWithComGoodowRealtimeJsonJsonObject? But when app comes to foreground, readystate is not yet open so this exception is thrown. Is there any reason for throwing an exception instead of returning immediately?
Very likely, just debug and inspect to find the execution workflow.
if getReadyState() != State.OPEN then return silently the sending data will be lost, maybe we should log a warning instead of throwing an exception.
I just let my app enters background for a while. When it comes to foreground, it does stop there. So I will go ahead and fix it by your suggestion. Could you please let me know if you find another way to fix it?