TheGrandmother / MUD

The worlds lames mud :/
1 stars 1 forks source link

server occassionally crashes on registration #32

Closed TheGrandmother closed 8 years ago

TheGrandmother commented 8 years ago

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.

TheGrandmother commented 8 years ago

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.

Chilinot commented 8 years ago

I added all outgoing messages to the debug logging. It might clear something up if this happens again. Commit: 32a916461a816ff7121f1626554a31c24f6eeb7d

TheGrandmother commented 8 years ago

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.

Chilinot commented 8 years ago

That means the timeout does not trigger fast enough for it to detect it in time. I will look into it.

TheGrandmother commented 8 years ago

We should also just slap a try catch clause in the adapter so that it does not kill the entire game engine.

Chilinot commented 8 years ago

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.

TheGrandmother commented 8 years ago

Well yes i also realized that the heartbeats where silly :p

Maybe we should keep a session id for all connections?

Chilinot commented 8 years ago

Is this issue still a problem?

TheGrandmother commented 8 years ago

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

Chilinot commented 8 years ago

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.

Chilinot commented 8 years ago

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==;