GDChannel icon indicating copy to clipboard operation
GDChannel copied to clipboard

App often crashes at INVALID_STATE_ERR

Open angeloh opened this issue 11 years ago • 4 comments

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.

angeloh avatar Oct 17 '14 00:10 angeloh

Try to debug with ReconnectBus The java version: ReconnectBus.send

Maybe use Xcode or Eclipse's Exception Breakpoint, then inspect which data is sending.

larrytin avatar Oct 17 '14 13:10 larrytin

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?

angeloh avatar Oct 17 '14 15:10 angeloh

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.

larrytin avatar Oct 18 '14 00:10 larrytin

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?

angeloh avatar Oct 18 '14 00:10 angeloh