server occassionally crashes on registration
Closed this issue · 11 comments
Server occasionally crashes on registration.
[8:59:5][INFO] A new connection has been established! IP: 130.243.249.10
[8:59:13][INFO] IP: 130.243.249.10 sent message: c2VydmVy;cHBw;HANDSHAKE;null;1450101553471;
[8:59:15][INFO] IP: 130.243.249.10 sent message: c2VydmVy;cHBw;REGISTRATION;null;1450101555559;cHBw;cHBwcA==;
[8:59:15][FINE] Received message from client. Calling execute action.
[8:59:15][SEVERE] null
Stack trace:
org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:573)
org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:550)
ioopm.mud.communication.websocket.WSServerAdapter.sendMessage(WSServerAdapter.java:194)
ioopm.mud.game.GameEngine.broadcastToRoom(GameEngine.java:73)
ioopm.mud.game.GameEngine.handleRegistrationRequest(GameEngine.java:164)
ioopm.mud.game.GameEngine.handleMessage(GameEngine.java:112)
ioopm.mud.Server.<init>(Server.java:84)
ioopm.mud.Main.main(Main.java:54)
Font know why, nothing weird with the input. Appears to be the broadcast to room that screws it up.
We really should fix so that the server logs the messages in plain text.
This happens when a broadcast message gets send, when a player has left the interface("connection closed") but the server have not removed the connection properly.
I added all outgoing messages to the debug logging. It might clear something up if this happens again. Commit: 32a9164
I know the reason why this error occurs.
Whena client navigates away from the page, the connection gets terminated but the user is not logged out. Which causes the game engine to crash on broadcast messages since it will try to send a message to a player which exists in the room but have no connection.
That means the timeout does not trigger fast enough for it to detect it in time. I will look into it.
We should also just slap a try catch clause in the adapter so that it does not kill the entire game engine.
I dont think that would be necessary. I have noticed that the logger spits out "ip-adress ... connection terminated" but without the "... was removed from legit connections". This means that clients that refreshes or closes their tab/browser still properly terminate the connection rendering the heartbeats useless. It's just the websocket lib that is not properly telling my serveradapter who closed their connection so the adapter dont know who to remove. Im currently looking into this.
Well yes i also realized that the heartbeats where silly :p
Maybe we should keep a session id for all connections?
Is this issue still a problem?
I have not tested it in a few days have been working with the encoding problem.
But just restart the server register a player, reload the browser without logging out and then immigrant try to register a new player.
If it does not crash the issue is solved
I just did, and it seems to be working. The connection was terminated but the game was not told. When the game then tried to broadcast to that closed connection the serveradapter detected that it was closed thanks to the new commit and then told the game about it.
Excerpt from game log showing what happened:
[17:20:46][INFO] IP: 83.251.53.149 sent message: c2VydmVy;bHVjYXM=;HEARTBEAT;null;1450477273546;
[17:20:51][INFO] IP: 83.251.53.149 sent message: c2VydmVy;bHVjYXM=;HEARTBEAT;null;1450477278546;
[17:20:56][INFO] A connection has been terminated! IP: 83.251.53.149
[17:20:57][INFO] A new connection has been established! IP: 83.251.53.149
[17:21:28][INFO] IP: 83.251.53.149 sent message: c2VydmVy;YXNkZg==;HANDSHAKE;null;1450477314844;
[17:21:29][INFO] IP: 83.251.53.149 sent message: c2VydmVy;YXNkZg==;REGISTRATION;null;1450477316675;YXNkZg==;YXNkZg==;
[17:21:29][FINE] Received message from client. Calling execute action.
[17:21:29][INFO] Connection to user "lucas" was apparently closed! Removing user from server...
[17:21:29][FINE] Attempting to send message: YXNkZg==;c2VydmVy;REGISTRATION_REPLY;null;1450477289936;dHJ1ZQ==;bnVsbA==;