Re: One client sending wrong data -> other clients disconnected

171 views
Skip to first unread message

Deathpat

unread,
May 5, 2013, 12:03:27 PM5/5/13
to kryone...@googlegroups.com
I've been debuging a bit, and it seems that the issue comes from the state of the Input present in KryoSerialization after one read fails.
I've tried to add:

input.setInputStream(byteBufferInputStream);

just after byteBufferInputStream.setByteBuffer(buffer); in the read method to reset it's state:

public synchronized Object read (Connection connection, ByteBuffer buffer) {
byteBufferInputStream.setByteBuffer(buffer);
input.setInputStream(byteBufferInputStream);
kryo.getContext().put("connection", connection);
return kryo.readClassAndObject(input);
}

And it fixes the issue for my case.
I'm absolutely not sure about my fix here, so maybe you can validate it :) It doesn't break my game so that's a good start ... :)

Cheers,
Patrice.

Le mardi 23 avril 2013 12:34:00 UTC+2, Deathpat a écrit :
Hi Nate,

I'm having an issue in my game that is quite annoying :
Having a server running with active connections, if one of the client sends some wrong data ( unregistered class, or any wrong data sent with or without kryonet  ), the client is disconnected ( which is all right ), but then the other connected clients get disconnected as well after having issues reading incoming messages.

I'm joining a zip file containing an eclipse project to reproduce the issue.
There are two classes:
first run TestServer
this one runs a server, and then runs a client ( connection 1 ) that asks for an update of the ping every 2 seconds.

then run TestClient
this one connects to the server ( connection 2 ) and then sends an object that is not registered on the server.

The result is that an exception is caused by the connection 2 sending the unregistered class :
com.esotericsoftware.kryo.KryoException: Encountered unregistered class ID: 14
it gets disconnected.

But then the Ping message sent by connection 1 is also provoking a KryoException: Encountered unregistered class ID: 119, and it gets closed as well.

Could you please help me with this issue ?

Thanks !
Patrice.

Nate

unread,
May 5, 2013, 3:39:05 PM5/5/13
to kryone...@googlegroups.com
Hi Patrice,

Good find! I've commit a similar change.

-Nate


--
You received this message because you are subscribed to the "kryonet-users" group.
http://groups.google.com/group/kryonet-users
---
You received this message because you are subscribed to the Google Groups "kryonet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kryonet-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Deathpat

unread,
May 5, 2013, 7:36:43 PM5/5/13
to kryone...@googlegroups.com
Hi,

I tried with your fix (input.rewind() instead of input.setInputStream(...)) and I have an immediate exception launching the TestServer from the project I attached in my first post.

setInputStream is setting the limit=0, and rewind is not .. so that's maybe the reason :)

Here is the trace I get with rewind :

00:00 TRACE: [kryonet] Server listener added: test.TestServer
00:00 TRACE: [kryonet] Server thread started.
00:00 DEBUG: [kryonet] Accepting connections on port: 0.0.0.0/0.0.0.0:666/TCP
00:00 DEBUG: [kryonet] Accepting connections on port: 0.0.0.0/0.0.0.0:667/UDP
00:00  INFO: [kryonet] Server opened.
00:00 TRACE: [kryonet] Connection listener added: test.TestServer$ClientListener
00:00 TRACE: [kryonet] Client listener added.
00:00 TRACE: [kryonet] Client thread started.
00:00  INFO: Connecting: /127.0.0.1:666/667
00:00 DEBUG: [kryonet] Port 666/TCP connected to: /127.0.0.1:59520
00:00 TRACE: [kryonet] Connection listener added: com.esotericsoftware.kryonet.Server$1
00:00 TRACE: [kryonet] Connection 1 sent TCP: RegisterTCP (6)
00:00 DEBUG: [kryonet] Port 59520/TCP connected to: /127.0.0.1:666
00:00 TRACE: [kryonet] Connection 1 received TCP: RegisterTCP
00:00 TRACE: [kryonet] Connection 1 sent TCP: RegisterUDP (6)
00:00 DEBUG: [kryonet] Port 667/UDP connected to: /127.0.0.1:58713
00:00  INFO: [kryonet] Connection 1 connected: /127.0.0.1
00:00 ERROR: [kryonet] Error updating connection.
com.esotericsoftware.kryonet.KryoNetException: Incorrect number of bytes (2 remaining) used to deserialize object: com.esotericsoftware.kryonet.FrameworkMessage$RegisterTCP@1922221
at com.esotericsoftware.kryonet.TcpConnection.readObject(TcpConnection.java:150)
at com.esotericsoftware.kryonet.Client.update(Client.java:246)
at com.esotericsoftware.kryonet.Client.run(Client.java:324)
at java.lang.Thread.run(Thread.java:662)
00:00 TRACE: [kryonet] Unable to read TCP from: Connection 1
java.net.SocketException: Connection is closed.
at com.esotericsoftware.kryonet.TcpConnection.readObject(TcpConnection.java:109)
at com.esotericsoftware.kryonet.Server.update(Server.java:197)
at com.esotericsoftware.kryonet.Server.run(Server.java:355)
at java.lang.Thread.run(Thread.java:662)
Exception in thread "Client" com.esotericsoftware.kryonet.KryoNetException: Incorrect number of bytes (2 remaining) used to deserialize object: com.esotericsoftware.kryonet.FrameworkMessage$RegisterTCP@1922221
at com.esotericsoftware.kryonet.TcpConnection.readObject(TcpConnection.java:150)
at com.esotericsoftware.kryonet.Client.update(Client.java:246)
at com.esotericsoftware.kryonet.Client.run(Client.java:324)
at java.lang.Thread.run(Thread.java:662)
00:00  INFO: [kryonet] Connection 1 disconnected.
java.net.SocketException: Connection is closed.
at com.esotericsoftware.kryonet.UdpConnection.send(UdpConnection.java:99)
at com.esotericsoftware.kryonet.Client.connect(Client.java:179)
at com.esotericsoftware.kryonet.Client.connect(Client.java:110)
at test.TestServer.start(TestServer.java:29)
at test.TestServer.main(TestServer.java:64)

Patrice.

Nate

unread,
May 6, 2013, 4:48:24 AM5/6/13
to kryone...@googlegroups.com
Gah, sorry about that. That's what I get for trying to be creative. I've committed your exact fix. :)

-Nate
Reply all
Reply to author
Forward
0 new messages