forresthopkinsa / StompProtocolAndroid

Websockets on Android
MIT License
11 stars 4 forks source link

Crash on unsubscribe from topic after ERROR is received #8

Open stairs opened 6 years ago

stairs commented 6 years ago

When socket error is reported and we try to unsubscribe from the topic, IllegalStateException will be thrown as shown below:

    @NonNull
    @Override
    public Completable send(String stompMessage) {
        return Completable.fromCallable(() -> {
            if (getSocket() == null) {
                throw new IllegalStateException("Not connected yet");
            } else {
                Log.d(TAG, "Send STOMP message: " + stompMessage);
                rawSend(stompMessage);
                return null;
            }
        });
    }

Could we maybe just check when unsubscribing if actual event should be sent based on sockets state?

forresthopkinsa commented 6 years ago

I'll look into this more later today. Thanks for the report :)

stairs commented 6 years ago

Would you mind if I just create a quick fix to check if a connection is still live before trying to send unsubscribe event? Other possible quick solution would be to just log an attempt to send a message when the connection is closed instead of crashing the app.

forresthopkinsa commented 6 years ago

Hi! Sorry, I just got back from a vacation in Mexico :) sorry to keep you waiting!

I'll resume work on this today or tomorrow, but yeah, if you make a working fix then I'll totally look into that.

stairs commented 6 years ago

Glad to hear that you are back! Regarding the issue, I don't see a decent fix without exposing provider details. Would you mind if we just don't throw runtime exception on sending unsubscribe event?