wg / lettuce

Scalable Java Redis client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decoding State Error - PubSub

dansimpson opened this issue · comments

When acting as a pubsub channel and receiving a large number of messages the decoder finds itself in the wrong state. I attached a stack trace of the error (I added the stack trace to the handler)

To test, subscribe to a channel, then publish as quickly as possible (tight loop). The connection will be dropped, and resubscribe, and messages will be lost.

java.lang.IllegalArgumentException: No enum const class com.lambdaworks.redis.pubsub.PubSubOutput$Type.my_full_message_here

at java.lang.Enum.valueOf(Enum.java:196)
at com.lambdaworks.redis.pubsub.PubSubOutput$Type.valueOf(PubSubOutput.java:1)
at com.lambdaworks.redis.pubsub.PubSubOutput.set(PubSubOutput.java:50)
at com.lambdaworks.redis.protocol.RedisStateMachine.decode(RedisStateMachine.java:113)
at com.lambdaworks.redis.pubsub.PubSubCommandHandler.decode(PubSubCommandHandler.java:51)
at com.lambdaworks.redis.protocol.CommandHandler.messageReceived(CommandHandler.java:54)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:94)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processSelectedKeys(AbstractNioWorker.java:372)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:246)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:38)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

Any thoughts?

Thanks for the bug report! Could you try forcing your project to use the latest netty (3.4.5.Final) and see if that resolves the issue?

I gave that a shot, with no success. In the messageReceived method in the CommandHandler class I get all of the content I expect, so netty is pushing all the data up to the handler. I will see if I can get it working and submit a pull request.

I added a test, which helped me find the issue (when comparing with your tests)

https://github.com/dansimpson/lettuce/blob/master/src/test/java/com/lambdaworks/redis/PubSubCommandTest.java#L193

If using the RedisPubSubConnection to publish, the error is reproducible. So, I am not sure this is a bug, but I figured "RedisPubSubConnection" ought to be used for publishing, but in this case, it tends to break.

--Dan

Thanks Dan! Looks like publishing via a PubSubConnection reproduces the issue because it's really an async connection that doesn't block waiting for a response, thus generating a lot of messages quickly. Tricky but your test case was very helpful! I've pushed a commit that should fix the issue and a new version (2.1.0) is pending release to maven central.

I ran a quick test in my application and that fixed it! Thanks.