IllegalArgumentException

170 views
Skip to first unread message

Hsaka

unread,
Mar 26, 2010, 6:25:02 PM3/26/10
to kryonet-users
Hi Nate,

I got the latest version of kryo and kryonet to sign properly. Now,
however, the server is throwing the following exception occasionally
and seemingly randomly.. Hundreds of these are output to the server's
console and then it stops and the server continues running normally.

java.lang.IllegalArgumentException
at java.nio.Buffer.position(Buffer.java:
218)
at
com.esotericsoftware.kryonet.TcpConnection.send(TcpConnection.java:
177)
at
com.esotericsoftware.kryonet.Connection.sendTCP(Connection.java:
58)
at
com.esotericsoftware.kryonet.Server.sendToAllTCP(Server.java:
394)
at
server.AllFoursServer.sendConstantMessage(AllFoursServer.java:
153)
at server.AllFoursServer.access$3(AllFoursServer.java:
143)
at server.AllFoursServer$3.run(AllFoursServer.java:128)

During the exception spam, players report all sorts of weird anomalies
like not being able to play a card or the wrong card being played.. I
might have to revert version of kryo and kryonet that I was using
before (the one with the buffer underflow) for the while.

Nate

unread,
Mar 26, 2010, 6:49:36 PM3/26/10
to kryone...@googlegroups.com
That isn't good. I'm not seeing it in the KryoNet tests. Maybe we need tests that connect up more users? Or it could be some esoteric combination of things that cause a problem. I'll keep trying to reproduce it. If you can come up with any hints, that would be great.

-Nate



--
You received this message because you are subscribed to the "kryonet-users" group.
http://groups.google.com/group/kryonet-users

To unsubscribe from this group, send email to kryonet-users+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Hsaka

unread,
Mar 28, 2010, 12:27:23 AM3/28/10
to kryonet-users
Hey Nate,

I see the following in TcpConnection.java in the latest kryonet:

int start = writeBuffer.position();
writeBuffer.position(start + 1); //exception reports this line

According to the javadocs (http://java.sun.com/j2se/1.4.2/docs/api/
java/nio/Buffer.html#position(int)), position(int newPosition) will
throw an IllegalArgumentException if newPosition is negative or
greater than the limit. Are either of these possible? Maybe start is
sometimes equal to the buffer limit and then the call to
position(start + 1) blows up?

Nate

unread,
Mar 28, 2010, 2:42:36 AM3/28/10
to kryone...@googlegroups.com
I agree it is possible for start + 1 to be >= limit. Pretty annoying that ByteBuffer throws IllegalArgumentException. It means any time KryoNet advances the position it has to do bounds checking, then the ByteBuffer does bounds checking for a second time... unless I want to catch IllegalArgumentException, which is a bit gross...

Anyway, if start + 1 >= limit, it needs to throw a WriteBufferOverflowException exception because it is really a buffer overflow. This is caught in Connection#sendTCP, and the connection is closed.

Over a long period of time that your server is up, do you see any warnings that say, "Write buffer overflow, position/limit/capacity: ..."? If so, then I could believe that every once in a while the write buffer happens to be filled up exactly by the last object written. This would cause position == limit - 1 and the behavior you describe. The server keeps trying to write an object, and keeps blowing up with an IllegalArgumentException until the client disconnects.

If you never see that warning, then it is quite unlikely that the last object written always fills up the buffer exactly. If this is the case, then I would guess that some combination of the objects you are sending have found a serialization bug.

On a side note, I wonder if some sort of journal/playback mechanism would be useful.

-Nate


To unsubscribe from this group, send email to kryonet-users+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Hsaka

unread,
Mar 28, 2010, 3:04:16 AM3/28/10
to kryonet-users
I used to get "Write buffer overflow, position/limit/capacity: ..."
occasionally with kryo 0.92 and kryonet 0.9.. After upgrading to the
latest kryonet and kryo, I the following occasionally:

com.esotericsoftware.kryo.SerializationException: Unable to serialize
object of type: net.messages.ConstantMessage
at
com.esotericsoftware.kryonet.TcpConnection.send(TcpConnection.java:
190)


at
com.esotericsoftware.kryonet.Connection.sendTCP(Connection.java:
58)
at
com.esotericsoftware.kryonet.Server.sendToAllTCP(Server.java:
394)
at
server.AllFoursServer.sendConstantMessage(AllFoursServer.java:
153)
at server.AllFoursServer.access$3(AllFoursServer.java:
143)
at server.AllFoursServer$3.run(AllFoursServer.java:
128)

Caused by: com.esotericsoftware.kryo.SerializationException: Buffer
limit exceeded serializing object of type: net.messa
ges.ConstantMessage
at
com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:
352)
at
com.esotericsoftware.kryonet.TcpConnection.send(TcpConnection.java:
183)
... 5
more
Caused by:
java.nio.BufferOverflowException
at java.nio.Buffer.nextPutIndex(Buffer.java:
495)
at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:
245)
at
com.esotericsoftware.kryo.serialize.LongSerializer.put(LongSerializer.java:
53)
at
com.esotericsoftware.kryo.serialize.LongSerializer.writeObjectData(LongSerializer.java:
32)
at
com.esotericsoftware.kryo.Serializer.writeObject(Serializer.java:
41)
at
com.esotericsoftware.kryo.serialize.FieldSerializer.writeObjectData(FieldSerializer.java:
165)
at
com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:
348)
... 6 more

On Mar 28, 2:42 am, Nate <nathan.sw...@gmail.com> wrote:
> I agree it is possible for start + 1 to be >= limit. Pretty annoying that
> ByteBuffer throws IllegalArgumentException. It means any time KryoNet
> advances the position it has to do bounds checking, then the ByteBuffer does
> bounds checking for a second time... unless I want to catch
> IllegalArgumentException, which is a bit gross...
>
> Anyway, if start + 1 >= limit, it needs to throw a
> WriteBufferOverflowException exception because it is really a buffer
> overflow. This is caught in Connection#sendTCP, and the connection is
> closed.
>
> Over a long period of time that your server is up, do you see any warnings
> that say, "Write buffer overflow, position/limit/capacity: ..."? If so, then
> I could believe that every once in a while the write buffer happens to be
> filled up exactly by the last object written. This would cause position ==
> limit - 1 and the behavior you describe. The server keeps trying to write an
> object, and keeps blowing up with an IllegalArgumentException until the
> client disconnects.
>
> If you never see that warning, then it is quite unlikely that the last
> object written always fills up the buffer exactly. If this is the case, then
> I would guess that some combination of the objects you are sending have
> found a serialization bug.
>
> On a side note, I wonder if some sort of journal/playback mechanism would be
> useful.
>
> -Nate
>

> On Sat, Mar 27, 2010 at 9:27 PM, Hsaka <akash.harri...@gmail.com> wrote:
> > Hey Nate,
>
> > I see the following in TcpConnection.java in the latest kryonet:
>
> > int start = writeBuffer.position();
> > writeBuffer.position(start + 1);    //exception reports this line
>
> > According to the javadocs (http://java.sun.com/j2se/1.4.2/docs/api/

> > java/nio/Buffer.html#position(int)<http://java.sun.com/j2se/1.4.2/docs/api/%0Ajava/nio/Buffer.html#posit...>),

Nate

unread,
Mar 28, 2010, 7:10:59 AM3/28/10
to kryone...@googlegroups.com
Ah. I see the error handling needs some changes. With my latest check in, if a client stops reading without disconnecting and the server queues up objects until the write buffer overflows, then the client is closed and a message is logged at DEBUG. This follows the same pattern as when a socket is suddenly closed (or when an IOException otherwise happens during communication).

I have identified everywhere in both Kryo and KryoNet that attempts to move the buffer position forward, and it is now handled like any other buffer overflow. This is also checked in.

Hopefully that takes care of the problems you were experiencing. Let me know how your stress tes... I mean how your game runs with the latest code. ;) I appreciate your willingness to go through a little pain as the project improves! :)

-Nate


To unsubscribe from this group, send email to kryonet-users+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Hsaka

unread,
Mar 28, 2010, 11:42:23 AM3/28/10
to kryonet-users
Awesome Nate!

I'll let you know how it goes. BTW, is there a logo for kryo/kryonet
that I can include in the game?

Thanks alot.

Nate

unread,
Mar 28, 2010, 10:18:01 PM3/28/10
to kryone...@googlegroups.com
I just redid the logos. I have zero artistic skills, but still I think it turned out OK(ish):
http://kryonet.googlecode.com/svn/wiki/kryonet-logo.jpg
Feel free to resize it, cut it up, or whatever as you like. Also, I am open to improving the logo. :)

-Nate


To unsubscribe from this group, send email to kryonet-users+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Hsaka

unread,
Mar 30, 2010, 1:17:53 PM3/30/10
to kryonet-users
Hi Nate,

Thanks for the logo, I added it.
No exceptions so far (:

Reply all
Reply to author
Forward
0 new messages