daniel-sc / rocketchat-modern-client

Client SDK for https://rocket.chat employing reactive style.
MIT License
11 stars 11 forks source link

The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method #7

Closed tuxmartin closed 5 years ago

tuxmartin commented 5 years ago

Hi, I have problem with websocket connection.

My rocketchat-notificator connected to rocket.chat yeasterday at 22:15 and everything worked great. But at today morning I looked at chat and there are no new messages.

My app connect to rocket chat after start and after that not closing websocket connection.

In application log I foud:

Mar 10 06:26:55 vpn rocketchat-notificator[27803]: java.util.concurrent.CompletionException: java.lang.IllegalStateException: Message will not be sent because the WebSocket session has been 
closed
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:961)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:926)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:442)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at java.lang.Thread.run(Thread.java:748)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: Caused by: java.lang.IllegalStateException: Message will not be sent because the WebSocket session has been closed
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.writeMessagePart(WsRemoteEndpointImplBase.java:425)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessage(WsRemoteEndpointImplBase.java:381)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$TextMessageSendHandler.write(WsRemoteEndpointImplBase.java:803)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendStringByCompletion(WsRemoteEndpointImplBase.java:212)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at org.apache.tomcat.websocket.WsRemoteEndpointAsync.sendText(WsRemoteEndpointAsync.java:47)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at com.github.daniel_sc.rocketchat.modern_client.RocketChatClient.sendDirect(RocketChatClient.java:124)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at com.github.daniel_sc.rocketchat.modern_client.RocketChatClient.lambda$send$6(RocketChatClient.java:115)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:952)
Mar 10 06:26:55 vpn rocketchat-notificator[27803]: #011... 3 more
Mar 10 06:26:56 vpn rocketchat-notificator[27803]: java.util.concurrent.CompletionException: java.lang.IllegalStateException: The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method
Mar 10 06:26:56 vpn rocketchat-notificator[27803]: #011at java.util.concurrent.Compl

and after that every sending message to chat fail on:

Mar 10 11:08:39 vpn rocketchat-notificator[27803]: #011at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1225)
Mar 10 11:08:39 vpn rocketchat-notificator[27803]: #011at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.textStart(WsRemoteEndpointImplBase.java:1187)
Mar 10 11:08:39 vpn rocketchat-notificator[27803]: #011at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendStringByCompletion(WsRemoteEndpointImplBase.java:209)
Mar 10 11:08:39 vpn rocketchat-notificator[27803]: #011at org.apache.tomcat.websocket.WsRemoteEndpointAsync.sendText(WsRemoteEndpointAsync.java:47)
Mar 10 11:08:39 vpn rocketchat-notificator[27803]: #011at com.github.daniel_sc.rocketchat.modern_client.RocketChatClient.sendDirect(RocketChatClient.java:124)
Mar 10 11:08:39 vpn rocketchat-notificator[27803]: #011at com.github.daniel_sc.rocketchat.modern_client.RocketChatClient.lambda$send$6(RocketChatClient.java:115)
Mar 10 11:08:39 vpn rocketchat-notificator[27803]: #011at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:952)
Mar 10 11:08:39 vpn rocketchat-notificator[27803]: #011... 3 more
Mar 10 11:08:39 vpn rocketchat-notificator[27803]: java.util.concurrent.CompletionException: java.lang.IllegalStateException: The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method

How can I solve this?

My code:

private RocketChatClient client;

public void connectToRocketChat() {     
    try {
        client = new RocketChatClient(rocketChatUrl, rocketChatUser, rocketChatPass);           
    } catch (Exception e) {
        e.printStackTrace();
    }               
}

is possible to do somothing like if (client.isConnected())? Or how can I check if app is still connected to rocket.chat?

Thanks for help.

daniel-sc commented 5 years ago

The PR #10 should help with this - it triggers exceptions on message send and subscriptions when the connection is closed. Right now the reconnect (new RocketChatClient...) is left to the user.