mrniko / netty-socketio

Socket.IO server implemented on Java. Realtime java framework
Apache License 2.0
6.82k stars 1.65k forks source link

ExceptionListener not used for errors in JSON parsing #198

Closed jvous closed 9 years ago

jvous commented 9 years ago

Hello, When a client emits invalid JSON, the error is simply logged by InPacketHandler with level ERROR, even though I a have an ExceptionListener with an overridden onJsonException set on Configuration, this is never called by the InPacketHandler. In fact, I can't seem to provoke any method calls on the custom ExceptionListener, but this might just be due to my limited knowledge of the code.

turbospaces commented 9 years ago

hi, this is not improvement, but really bug. Jackson support is wrapped into JsonSupportWrapper, and in case of error, library just hides error and returns NULL

public <T> T readValue(String namespaceName, ByteBufInputStream src, Class<T> valueType) throws IOException {
        try {
            return delegate.readValue(namespaceName, src, valueType);
        } catch (Exception e) {
            src.reset();
            log.error("Can't read value: " + src.readLine() + " for type: " + valueType, e);
            return null;
        }
    }

And later i'm getting NPE, no exception listeners are invoked.

2015-07-16 11:18:49.607|ERROR|c.c.s.h.InPacketHandler|nioEventLoopGroup-9-15|Error during data processing. Client sessionId: 7877c4a1-5779-4690-84fc-3ce680842fba, data: 
java.lang.NullPointerException: null
    at com.corundumstudio.socketio.protocol.PacketDecoder.parseBody(PacketDecoder.java:304) ~[netty-socketio-1.7.7.jar:na]
    at com.corundumstudio.socketio.protocol.PacketDecoder.decode(PacketDecoder.java:184) ~[netty-socketio-1.7.7.jar:na]
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "casinonameZ" (class com.pt.ums.GetPlayerInfoRequest), not marked as ignorable (2 known properties: "casinoname", "username"])
 at [Source: io.netty.buffer.ByteBufInputStream@f1f930c; line: 1, column: 148] (through reference chain: com.playtech.crossteam.socketio.pojo.SimpleRequestMessageWrapper["payload"]->com.pt.ums.GetPlayerInfoRequest["casinonameZ"])
    at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:51) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:817) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:958) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1324) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1302) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:249) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:169) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:144) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:124) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:95) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromAny(AsPropertyTypeDeserializer.java:167) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserializeWithType(UntypedObjectDeserializer.java:500) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:521) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:95) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap._findDeserializeAndSet2(BeanPropertyMap.java:313) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap.findDeserializeAndSet(BeanPropertyMap.java:291) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:248) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:136) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3534) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1870) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.corundumstudio.socketio.protocol.JacksonJsonSupport$EventDeserializer.deserialize(JacksonJsonSupport.java:194) ~[netty-socketio-1.7.7.jar:na]
    at com.corundumstudio.socketio.protocol.JacksonJsonSupport$EventDeserializer.deserialize(JacksonJsonSupport.java:155) ~[netty-socketio-1.7.7.jar:na]
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3562) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2648) ~[jackson-databind-2.5.3.jar:2.5.3]
    at com.corundumstudio.socketio.protocol.JacksonJsonSupport.readValue(JacksonJsonSupport.java:337) ~[netty-socketio-1.7.7.jar:na]
    at com.corundumstudio.socketio.JsonSupportWrapper.readValue(JsonSupportWrapper.java:52) ~[netty-socketio-1.7.7.jar:na]
    at com.corundumstudio.socketio.protocol.PacketDecoder.parseBody(PacketDecoder.java:303) [netty-socketio-1.7.7.jar:na]
    at com.corundumstudio.socketio.protocol.PacketDecoder.decode(PacketDecoder.java:184) [netty-socketio-1.7.7.jar:na]
    at com.corundumstudio.socketio.protocol.PacketDecoder.decodePackets(PacketDecoder.java:150) [netty-socketio-1.7.7.jar:na]
    at com.corundumstudio.socketio.handler.InPacketHandler.channelRead0(InPacketHandler.java:65) [netty-socketio-1.7.7.jar:na]
    at com.corundumstudio.socketio.handler.InPacketHandler.channelRead0(InPacketHandler.java:36) [netty-socketio-1.7.7.jar:na]
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:249) [netty-codec-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at com.corundumstudio.socketio.transport.WebSocketTransport.channelRead(WebSocketTransport.java:94) [netty-socketio-1.7.7.jar:na]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [netty-codec-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at com.corundumstudio.socketio.transport.PollingTransport.channelRead(PollingTransport.java:109) [netty-socketio-1.7.7.jar:na]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at com.corundumstudio.socketio.handler.AuthorizeHandler.channelRead(AuthorizeHandler.java:115) [netty-socketio-1.7.7.jar:na]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:108) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:244) [netty-codec-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) [netty-transport-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111) [netty-common-4.0.28.Final.jar:4.0.28.Final]
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) [netty-common-4.0.28.Final.jar:4.0.28.Final]
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]

Steps to reproduce are obvious, configure Jackson to fail on unknown fields and send invalid field.

mrniko commented 9 years ago

fixed

mrniko commented 9 years ago

onJsonException and onMessageException methods are used in socketio protocol prior 1.0 version so i removed it.

enflout commented 9 years ago

I like this task! @mrniko, where will be a release date of 1.7.8?

mrniko commented 9 years ago

@enflout at the end of november