apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.41k stars 26.42k forks source link

NPE when use netty3 and kryo2 #7048

Open zhangyz-hd opened 3 years ago

zhangyz-hd commented 3 years ago

Environment

Steps to reproduce this issue

  1. A provider with server=netty3 and serialization=kryo2
    dubbo.protocol.server=netty3
    dubbo.protocol.serialization=kryo2
    dubbo.protocol.heartbeat=5000
  2. A consumer with client=netty3
    dubbo.consumer.client=netty3
  3. An NPE occurred when a heartbeat invoker between the provider and the consumer. Because heartbeat Request/Response data is always null.

Pls. provide [GitHub address] to reproduce this issue. https://github.com/zhangyz-hd/dubbo-issues

If there is an exception, please attach the exception trace:

org.apache.dubbo.remoting.RemotingException: Failed to send message Request [id=6, version=2.0.2, twoway=true, event=true, broken=false, data=null] to /192.168.1.122:20881, cause: null
    at org.apache.dubbo.remoting.transport.netty.NettyChannel.send(NettyChannel.java:113)
    at org.apache.dubbo.remoting.transport.AbstractClient.send(AbstractClient.java:178)
    at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeChannel.send(HeaderExchangeChannel.java:98)
    at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeChannel.send(HeaderExchangeChannel.java:87)
    at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeClient.send(HeaderExchangeClient.java:120)
    at org.apache.dubbo.remoting.exchange.support.header.HeartbeatTimerTask.doTask(HeartbeatTimerTask.java:53)
    at org.apache.dubbo.remoting.exchange.support.header.AbstractTimerTask.run(AbstractTimerTask.java:87)
    at org.apache.dubbo.common.timer.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:648)
    at org.apache.dubbo.common.timer.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:727)
    at org.apache.dubbo.common.timer.HashedWheelTimer$Worker.run(HashedWheelTimer.java:449)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
    at org.apache.dubbo.common.serialize.kryo.optimized.KryoObjectOutput2.writeObject(KryoObjectOutput2.java:104)
    at org.apache.dubbo.common.serialize.ObjectOutput.writeEvent(ObjectOutput.java:53)
    at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encodeEventData(ExchangeCodec.java:377)
    at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encodeEventData(ExchangeCodec.java:429)
    at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encodeRequest(ExchangeCodec.java:236)
    at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encode(ExchangeCodec.java:69)
    at org.apache.dubbo.rpc.protocol.dubbo.DubboCountCodec.encode(DubboCountCodec.java:40)
    at org.apache.dubbo.remoting.transport.netty.NettyCodecAdapter$InternalEncoder.encode(NettyCodecAdapter.java:84)
    at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:66)
    at org.apache.dubbo.remoting.transport.netty.NettyHandler.writeRequested(NettyHandler.java:110)
    at org.jboss.netty.channel.Channels.write(Channels.java:611)
    at org.jboss.netty.channel.Channels.write(Channels.java:578)
    at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:251)
    at org.apache.dubbo.remoting.transport.netty.NettyChannel.send(NettyChannel.java:103)
    ... 10 more
dkisser commented 3 years ago

change serialization to "kryo", the "kryo2" not support event , it may have another purpose.The reason of the NPE is that the data of channel event is null .it's outputObject will use Kryo.writeObjectOrNull(Output output, Object object, Class type), when use "kryo2" . data is null ,so that data.getClass() will throw NPE. kery2error

zhangyz-hd commented 3 years ago

change serialization to "kryo", the "kryo2" not support event , it may have another purpose.The reason of the NPE is that the data of channel event is null .it's outputObject will use Kryo.writeObjectOrNull(Output output, Object object, Class type), when use "kryo2" . data is null ,so that data.getClass() will throw NPE. kery2error

I know that kryo2 was not publid. But when I added a method to org.apache.dubbo.common.serialize.Serialization, kryo2 caused me some trouble, so I should delete kryo2 implements?