EsotericSoftware / kryonet

TCP/UDP client/server library for Java, based on Kryo
BSD 3-Clause "New" or "Revised" License
1.81k stars 415 forks source link

ERROR all.minlog.MinlogToSLF4JLogger - kryonet: Error reading TCP from connection: Connection 2 #150

Closed admly closed 5 years ago

admly commented 5 years ago

Hello, I've got an issue which seems to be a kryonet used by InspectIT project. It seems like kryonet lacks log4j? Sometimes it works like a charm, sometimes it crashes a lot. Could you give a clue about how to investigate this one? We're using newest KryoNet version.

[ Server] INFO all.minlog.MinlogToSLF4JLogger - kryonet: Connection 1 connected: /x.x.x.x [ervice-thread-1] INFO r.util.AgentStatusDataProvider - Platform 1552 has been reconnected, but no class cache is available for this agent. Please reconnect the agent, to reload the class cache. [ervice-thread-2] INFO er.service.RegistrationService - Trying to unregister the Agent with the ID 1552 [ervice-thread-2] INFO er.service.RegistrationService - The Agent with the ID 1552 has been successfully unregistered. [ Server] INFO all.minlog.MinlogToSLF4JLogger - kryonet: Connection 1 disconnected. [ Server] INFO all.minlog.MinlogToSLF4JLogger - kryonet: Connection 2 connected: /10.0.142.181 [ervice-thread-0] INFO er.service.RegistrationService - Trying to register Agent 'xxx' [ervice-thread-0] INFO er.service.RegistrationService - Successfully registered the Agent 'xxx' with id 1552, version 1.8.0.0 and following network interfaces: [ervice-thread-0] INFO er.service.RegistrationService - |- IPv4: x.x.x.x [ervice-thread-0] INFO er.service.RegistrationService - |- IPv4: 127.0.0.1 [ervice-thread-0] INFO er.service.RegistrationService - |- IPv6: 0:0:0:0:0:0:0:1%lo [ervice-thread-0] INFO er.service.RegistrationService - |- IPv6: X:X:X:X [ Server] ERROR all.minlog.MinlogToSLF4JLogger - kryonet: Error reading TCP from connection: Connection 2 java.lang.ClassNotFoundException: org.apache.logging.log4j.spi.ExtendedLogger at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:136) ... 18 common frames omitted Wrapped by: com.esotericsoftware.kryo.KryoException: Unable to find class: org.apache.logging.log4j.spi.ExtendedLogger Serialization trace: methods (rocks.inspectit.shared.all.instrumentation.classcache.InterfaceType) at com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:138) at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:115) at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:641) at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:752) at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:116) at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:22) at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:679) at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:106) at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:528) at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:761) at rocks.inspectit.shared.all.kryonet.rmi.ObjectSpace$InvokeMethod.read(ObjectSpace.java:652) at com.esotericsoftware.kryo.serializers.DefaultSerializers$KryoSerializableSerializer.read(DefaultSerializers.java:433) at com.esotericsoftware.kryo.serializers.DefaultSerializers$KryoSerializableSerializer.read(DefaultSerializers.java:425) at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:761) at rocks.inspectit.shared.all.kryonet.ExtendedSerializationImpl.read(ExtendedSerializationImpl.java:163) at rocks.inspectit.shared.all.kryonet.TcpConnection.readObject(TcpConnection.java:209) ... 3 common frames omitted Wrapped by: com.esotericsoftware.kryonet.KryoNetException: Error during deserialization. at rocks.inspectit.shared.all.kryonet.TcpConnection.readObject(TcpConnection.java:211) at rocks.inspectit.shared.all.kryonet.Server.update(Server.java:256) at rocks.inspectit.shared.all.kryonet.Server.run(Server.java:452) at java.lang.Thread.run(Thread.java:748)

[ervice-thread-1] ERROR tExtendedByteBufferInputStream - Error reading from the socket channel. java.nio.channels.ClosedChannelException: null at sun.nio.ch.SocketChannelImpl.ensureReadOpen(SocketChannelImpl.java:257) at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:300) at rocks.inspectit.shared.all.storage.nio.stream.SocketExtendedByteBufferInputStream$SocketReadRunnable.run(SocketExtendedByteBufferInputStream.java:160) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748)

crykn commented 5 years ago

As the minlog dependency (and the actual error in yout trace) is actually a part of Kryo I would recommend trying to use kryonet with a later version of Kryo. If you don't want to update the dependency yourself you can take a look at the forks that are already doing that.

admly commented 5 years ago

We are struggling to leverage the Kryo version because of problems with backward compatibility. We'll see.

crykn commented 5 years ago

The problem you're encountering stems from this piece of code: DefaultClassResolver.java#L136. So basically your server is receiving a message and when trying to deserialize it he checks the ID of the class (which maps to org.apache.logging.log4j.spi.ExtendedLogger) and then notices this class is not registered in Kryo. The most likely cause for this is that you fail to register (kryo.register(SomeClass.class);) your classes to the server and client Kryo in the same way.

NathanSweet commented 5 years ago

Thanks @crykn. Looks like application code needs to register a class.