[SOLVED] CancelledKeyException in SpiderMonkey

Hey,



since I didn’t see Levia online for a few days I thought I just write here. Maybe someone else can help me.



Every once in a while the Server of Marble Mania crashes with this Exception:



WARNUNG: [Server#1][TCP] Connection was closed before we could read. Disconnected client.

Exception in thread “Thread-1” java.nio.channels.CancelledKeyException

at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:55)

at sun.nio.ch.SelectionKeyImpl.interestOps(SelectionKeyImpl.java:64)

at com.jme3.network.connection.Client.send(Client.java:232)

at de.bazinga.marblemania.network.server.connections.Connection.sendMessage(Connection.java:78)

at de.bazinga.marblemania.network.server.MarbleServer.sendToAll(MarbleServer.java:318)

at de.bazinga.marblemania.network.server.MarbleServer.updateUserlist(MarbleServer.java:294)

at de.bazinga.marblemania.network.server.listener.MessageListener.messageReceived(MessageListener.java:42)

at com.jme3.network.connection.Connection.fireMessageReceived(Connection.java:346)

at com.jme3.network.connection.TCPConnection.read(TCPConnection.java:204)

at com.jme3.network.connection.Connection.run(Connection.java:124)

at com.jme3.network.connection.ConnectionRunnable.run(ConnectionRunnable.java:77)

at java.lang.Thread.run(Thread.java:619)






From the Exception and the StackTrace I guess, that a Client disconnects and when he disconnects I call the method sendToAll() and send every Client an update of the Userlist.

And when I call sendToAll() the Server crashes. But it only happens like once every weeks or so. I guess it has something to do, how the Client disconnects, but I couldn’t reproduce it yet.

I know it’s not very much Information, but I don’t know much more. It’s basically just, that a Client disconnects and right after that sendToAll() is called and that it crashes.

Maybe somebody knows a Solution or has an hint?





Greets,

Dennis

I can reproduce it. It happens when you call send() outside the network thread, when a player is about to be disconnected.

Since the client is disconnected, the send() call should detect that and fail silently on that particular player since he is not online anymore.

Ahh…okay. That would explain it. Thanks!



But how can I prevent this? Can I somehow add it somewhere so that the Message is send in the network thread after all disconnects are done?



And if you can reproduce it, could you maybe show me the Code that causes the Error. I understand why it happens, but I’m not quite sure which part of my Code causes it, because I only saw the Exception in my Log-Files, but it didn’t happen to me yet.

Usually updateUserlist(), which sends the message to all clients, is called in the clientDisconnected(Client) and I figured that should work. It’s also called at some other placed, but it’s only called after I received a Message from the Client.



If you don’t have the code anymore, don’t worry about it :wink:

Momoko_Fan said:
I can reproduce it. It happens when you call send() outside the network thread, when a player is about to be disconnected.
Since the client is disconnected, the send() call should detect that and fail silently on that particular player since he is not online anymore.

I'll look into this.

This has been fixed.