NaikSoftware / StompProtocolAndroid

STOMP protocol via WebSocket for Android
MIT License
597 stars 265 forks source link

Pending unsubscribe request crashes the program on the next connection #201

Closed cicciob95 closed 3 years ago

cicciob95 commented 3 years ago

After calling disconnect directly, there remains a pending unsubscribe request that crashes the program on the next connection.

D/AbstractConnectionProvider: Emit lifecycle event: OPENED
D/AbstractConnectionProvider: Send STOMP message: CONNECT
.....
D/StompClient: Publish open
D/AbstractConnectionProvider: Receive STOMP message: CONNECTED
....
D/AbstractConnectionProvider: Send STOMP message: SUBSCRIBE
    id:f0f48748-ceb4-45a1-9a58-796456b3d79a
    destination:/queue/utente.PRRFNC77S10D095T
.....
D/StompClient: Stomp disconnected
D/StompClient: Unsubscribe path: /queue/utente.PRRFNC77S10D095T id: f0f48748-ceb4-45a1-9a58-796456b3d79a
D/AbstractConnectionProvider: Emit lifecycle event: CLOSED

--------------------------------------------------------
RECONNECT WITHOUT CLOSING APP
--------------------------------------------------------

D/AbstractConnectionProvider: Emit lifecycle event: OPENED
D/AbstractConnectionProvider: Send STOMP message: CONNECT
....
D/StompClient: Publish open
I/ample.energyap: NativeAlloc concurrent copying GC freed 64286(2618KB) AllocSpace objects, 2(36KB) LOS objects, 49% free, 4006KB/8013KB, paused 530us total 101.962ms
I/ample.energyap: WaitForGcToComplete blocked ClassLinker on HeapTrim for 86.915ms
D/AbstractConnectionProvider: Receive STOMP message: CONNECTED
.....
D/AbstractConnectionProvider: Send STOMP message: UNSUBSCRIBE
    id:f0f48748-ceb4-45a1-9a58-796456b3d79a

    ��
    Send STOMP message: SUBSCRIBE
    id:fd751c50-9121-43a7-afd2-7fbe821be218
    destination:/queue/utente.PRRFNC77S10D095T
    ack:auto

    ��
D/AbstractConnectionProvider: Receive STOMP message: ERROR
    message:No subscription found
    content-type:text/plain
    version:1.0,1.1,1.2
    content-length:123

    UNSUBSCRIBE must refer to an existing subscription.
    Subscription to "id='f0f48748-ceb4-45a1-9a58-796456b3d79a'" not found.
    ��
W/System.err: io.reactivex.exceptions.OnErrorNotImplementedException: The exception was not handled due to missing onError handler in the subscribe() method call.

I thought about unsubscribing just before disconnecting, but even if the application does not crash, the socket is closed after attempting the connection.

D/AbstractConnectionProvider: Emit lifecycle event: OPENED
D/AbstractConnectionProvider: Send STOMP message: CONNECT
....
D/StompClient: Publish open
D/AbstractConnectionProvider: Receive STOMP message: CONNECTED
.......
D/AbstractConnectionProvider: Send STOMP message: SUBSCRIBE
    id:feb2659a-7b70-44fd-ade3-fe359537ba25
    destination:/queue/utente.BFNCFD67K07S458T
......
D/EGL_emulation: eglMakeCurrent: 0xd68c4600: ver 2 0 (tinfo 0xd6831620)
D/EGL_emulation: eglMakeCurrent: 0xd68c4600: ver 2 0 (tinfo 0xd6831620)
D/EGL_emulation: eglMakeCurrent: 0xd68c4600: ver 2 0 (tinfo 0xd6831620)
I/AssistStructure: Flattened final assist data: 4044 bytes, containing 1 windows, 27 views
D/EGL_emulation: eglMakeCurrent: 0xd68c4600: ver 2 0 (tinfo 0xd6831620)
I/chatty: uid=10134(com.example.energyapp) RenderThread identical 1 line
D/EGL_emulation: eglMakeCurrent: 0xd68c4600: ver 2 0 (tinfo 0xd6831620)
D/StompClient: Stomp disconnected
D/StompClient: Unsubscribe path: /queue/utente.BFNCFD67K07S458T id: feb2659a-7b70-44fd-ade3-fe359537ba25
--------------------------------------------------------
RECONNECT WITHOUT CLOSING APP
--------------------------------------------------------
D/AbstractConnectionProvider: Emit lifecycle event: OPENED
    Send STOMP message: CONNECT
.....
D/StompClient: Publish open
D/AbstractConnectionProvider: Receive STOMP message: CONNECTED
....
D/AbstractConnectionProvider: Send STOMP message: UNSUBSCRIBE
    id:feb2659a-7b70-44fd-ade3-fe359537ba25
D/AbstractConnectionProvider: Send STOMP message: SUBSCRIBE
    id:8b195dc1-ea4d-4b05-b5b5-315c32dc4536
    destination:/queue/utente.PRRFNC77S10D095T
D/AbstractConnectionProvider: Receive STOMP message: ERROR
    message:No subscription found
    .....
    UNSUBSCRIBE must refer to an existing subscription.
    Subscription to "id='feb2659a-7b70-44fd-ade3-fe359537ba25'" not found.

E/StompClient: Error parsing message
    java.util.NoSuchElementException
        at java.util.Scanner.skip(Scanner.java:1755)
        at java.util.Scanner.skip(Scanner.java:1772)
        at ua.naiksoftware.stomp.dto.StompMessage.from(StompMessage.java:89)
        at ua.naiksoftware.stomp.-$$Lambda$tOUk3h1Xq2DhmHKtfgaqt_E7Qh0.apply(Unknown Source:2)
        at io.reactivex.internal.operators.observable.ObservableMap$MapObserver.onNext(ObservableMap.java:57)
        at io.reactivex.internal.operators.observable.ObservableConcatMap$ConcatMapDelayErrorObserver$DelayErrorInnerObserver.onNext(ObservableConcatMap.java:506)
        at io.reactivex.subjects.PublishSubject$PublishDisposable.onNext(PublishSubject.java:308)
        at io.reactivex.subjects.PublishSubject.onNext(PublishSubject.java:228)
        at ua.naiksoftware.stomp.provider.AbstractConnectionProvider.emitMessage(AbstractConnectionProvider.java:117)
        at ua.naiksoftware.stomp.provider.OkHttpConnectionProvider$1.onMessage(OkHttpConnectionProvider.java:67)
        at okhttp3.internal.ws.RealWebSocket.onReadMessage(RealWebSocket.kt:333)
        at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.kt:245)
        at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.kt:106)
        at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.kt:293)
        at okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:195)
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
D/AbstractConnectionProvider: Emit lifecycle event: CLOSED
D/StompClient: Socket closed
    Stomp disconnected
D/StompClient: Unsubscribe path: /queue/utente.PRRFNC77S10D095T id: 8b195dc1-ea4d-4b05-b5b5-315c32dc4536

How can I do? Thanks

cicciob95 commented 3 years ago

I solved it by disposing CompositeDisposable before doing a disconnection.