Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalStateException error is thrown when the server is closed on a logged-in server #367

Open
tariksapmaz opened this issue Aug 22, 2024 · 0 comments

Comments

@tariksapmaz
Copy link

tariksapmaz commented Aug 22, 2024

What is the issue?

I am using soketi websocket server that uses a pusher protocol running locally. The userAuthentication feature is active in my server settings, as you know, so if you do not sign in, the server kicks me out of the websocket server after a certain period of time.

My problem is as follows, the android device sends a connection request to the open server and provides a connection by signing in after being connected as I show below. If I close the server, it repeats the disconnection error twice and tries to disconnect from the user it made null, which makes the application crash.

Maybe it's a bug in my usage or a problem in the library, I don't know, but it's very bad when the whole application crashes.

...

Is it a crash report? Submit stack traces or anything that you think would help

override fun onCreate(savedInstanceState: Bundle?) {
     super.onCreate(savedInstanceState)
     window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
     AAAA();
     BBBB();
     CCCC();
     setupWebSockets();
}

private fun setupWebSockets() {
        pusher = Pusher(Constants.WS_KEY, PusherConfiguration.generateConfig())
        val channel = pusher.subscribe("XXX.XXX.XXX")
        channel
                .bind("AAA.BBB.CCC") {
                        DDD();
                }
        pusher.connect(object : ConnectionEventListener {
              override fun onConnectionStateChange(change: ConnectionStateChange) {
	              websocketLastState = change.previousState
	              websocketCurrentState = change.currentState
              
	              Log.d(TAG, "Websocket state changed " + change.previousState + " -> " + change.currentState)
              
	              if (change.currentState == ConnectionState.CONNECTED) {
		              Log.d(TAG, "Socket ID: " + pusher.connection.socketId)
              
		              pusher.signin()
	              }
              }
              
              override fun onError(message: String?, code: String?, e: Exception?) {
	              Log.w(TAG, "There was a problem connecting!")
	              Log.w(TAG, "Message: ${message}, code: $code, exception: ${e?.javaClass?.name}", e)
              
	              if (code == "4009") {
		              if (message?.contains("You got disconnected by the app") == true) {
			              Log.w(TAG, "Kick from websocket!")
			              isKickedFromWebSocketServer = true;
		              } else {
			              // "Connection not authorized within timeout"
			              Log.w(TAG, "Auth to websocket failed or timeout!")
		              }
	              } else if (code == "4200") {
		              Log.w(TAG, "Server is down!")
              
	              }
              }
              }, ConnectionState.ALL)
}
2024-08-22 17:22:50.147 25509-25535 com.exam...$Companion com.example.example2              D  Websocket state changed DISCONNECTED -> CONNECTING
2024-08-22 17:23:09.378 25509-25509 com.exam...$Companion com.example.example2              D  Lorem ipsum12324232
2024-08-22 17:23:09.798 25509-25509 com.exam...$Companion com.example.example2              D  Lorem ipsum12324232
2024-08-22 17:23:05.619 25509-25535 com.exam...$Companion com.example.example2              D  Websocket state changed CONNECTING -> CONNECTED
2024-08-22 17:23:09.378 25509-25509 com.exam...$Companion com.example.example2              D  Lorem ipsum12324232
2024-08-22 17:23:09.798 25509-25509 com.exam...$Companion com.example.example2              D  Lorem ipsum12324232
2024-08-22 17:23:05.619 25509-25535 com.exam...$Companion com.example.example2              D  Socket ID: 4245098167.6681757448
2024-08-22 17:23:09.354 25509-25535 com.exam...$Companion com.example.example2              D  Websocket state changed CONNECTED -> RECONNECTING
2024-08-22 17:23:09.355 25509-25535 com.exam...$Companion com.example.example2              W  There was a problem connecting!
2024-08-22 17:23:09.356 25509-25535 com.exam...$Companion com.example.example2              W  Message: Server closed. Please reconnect shortly., code: 4200, exception: null
2024-08-22 17:23:09.356 25509-25535 com.exam...$Companion com.example.example2              W  Server is down!
2024-08-22 17:23:09.358 25509-25535 User                    com.example.example2            W  Server closed. Please reconnect shortly.
2024-08-22 17:23:09.361 25509-25509 com.exam...$Companion com.example.example2              D  Lorem ipsum12324232
2024-08-22 17:23:09.361 25509-25509 com.exam...$Companion com.example.example2              D  Lorem ipsum12324232
2024-08-22 17:23:09.363 25509-25509 com.exam...$Companion com.example.example2              D  Lorem ipsum12324232
2024-08-22 17:23:09.364 25509-25509 com.exam...$Companion com.example.example2              D  Lorem ipsum12324232
2024-08-22 17:23:09.378 25509-25509 com.exam...$Companion com.example.example2              D  Lorem ipsum12324232
2024-08-22 17:23:09.798 25509-25509 com.exam...$Companion com.example.example2              D  Lorem ipsum12324232
2024-08-22 17:23:10.358 25509-25535 com.exam...$Companion com.example.example2              D  Websocket state changed RECONNECTING -> CONNECTING
2024-08-22 17:23:10.404 25509-25535 com.exam...$Companion com.example.example2              D  Websocket state changed CONNECTING -> RECONNECTING
2024-08-22 17:23:10.404 25509-25535 com.exam...$Companion com.example.example2              W  There was a problem connecting!
2024-08-22 17:23:10.405 25509-25535 com.exam...$Companion com.example.example2              W  Message: Server is closing. Please reconnect shortly., code: 4200, exception: null
2024-08-22 17:23:10.405 25509-25535 com.exam...$Companion com.example.example2              W  Server is down!
2024-08-22 17:23:10.406 25509-25535 User                    com.example.example2              W  Server is closing. Please reconnect shortly.
2024-08-22 17:23:14.406 25509-25535 com.exam...$Companion com.example.example2              D  Websocket state changed RECONNECTING -> CONNECTING
2024-08-22 17:23:14.417 25509-25535 AndroidRuntime          com.example.example2              E  FATAL EXCEPTION: pusher-java-client eventQueue
                                                                                                    Process: com.example.example2, PID: 25509
                                                                                                    java.lang.IllegalStateException: User id is null in ServerToUserChannel
                                                                                                    	at com.pusher.client.user.impl.ServerToUserChannel.getName(ServerToUserChannel.java:20)
                                                                                                    	at com.pusher.client.user.impl.InternalUser.disconnect(InternalUser.java:139)
                                                                                                    	at com.pusher.client.user.impl.InternalUser.access$100(InternalUser.java:22)
                                                                                                    	at com.pusher.client.user.impl.InternalUser$ConnectionStateChangeHandler.onConnectionStateChange(InternalUser.java:43)
                                                                                                    	at com.pusher.client.connection.websocket.WebSocketConnection.lambda$updateState$3(WebSocketConnection.java:153)
                                                                                                    	at com.pusher.client.connection.websocket.WebSocketConnection$$ExternalSyntheticLambda6.run(Unknown Source:4)
                                                                                                    	at com.pusher.client.util.Factory.lambda$queueOnEventThread$0(Factory.java:140)
                                                                                                    	at com.pusher.client.util.Factory$$ExternalSyntheticLambda0.run(Unknown Source:2)
                                                                                                    	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:920)
2024-08-22 17:23:14.471 25509-25535 Process                 com.example.example2              I  Sending signal. PID: 25509 SIG: 9

...

Any improvements you suggest

To be honest, I don't know how to find a solution. The first thing that comes to my mind is to put the ```` setupWebSocket() `` function in try/catch and catch the error, but it was not a solution.
...


CC @pusher/mobile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant