Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnsupportedOperationException from ListSubscriber during hrandfieldWithvalues #3122

Closed
mshinn opened this issue Jan 11, 2025 · 2 comments · Fixed by #3123
Closed

UnsupportedOperationException from ListSubscriber during hrandfieldWithvalues #3122

mshinn opened this issue Jan 11, 2025 · 2 comments · Fixed by #3123
Labels
status: mre-available Minimal Reproducible Example is available type: bug A general bug
Milestone

Comments

@mshinn
Copy link

mshinn commented Jan 11, 2025

Bug Report

Current Behavior

I'm consistently seeing the following exception when calling hrandfieldWithvalues when there is only a single result returned. If multiple results are returned, the call succeeds.

Stack trace
java.lang.UnsupportedOperationException
	at java.base/java.util.AbstractList.add(AbstractList.java:153)
	at java.base/java.util.AbstractList.add(AbstractList.java:111)
	at io.lettuce.core.output.ListSubscriber.onNext(ListSubscriber.java:49)
	at io.lettuce.core.output.KeyValueListOutput.set(KeyValueListOutput.java:76)
	at io.lettuce.core.protocol.RedisStateMachine.safeSet(RedisStateMachine.java:809)
	at io.lettuce.core.protocol.RedisStateMachine.handleBytes(RedisStateMachine.java:596)
	at io.lettuce.core.protocol.RedisStateMachine$State$Type.handle(RedisStateMachine.java:206)
	at io.lettuce.core.protocol.RedisStateMachine.doDecode(RedisStateMachine.java:358)
	at io.lettuce.core.protocol.RedisStateMachine.decode(RedisStateMachine.java:319)
	at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:840)
	at io.lettuce.core.protocol.CommandHandler.decode0(CommandHandler.java:791)
	at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:765)
	at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:657)
	at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:597)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1357)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:868)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:840)

Input Code

Input Code
String key = "myKey";
redisClusterCommands.hset(key, "field1", "value1");
redisClusterCommands.hset(key, "field2", "value2");
//Collection<KeyValue<String, String>> values1 = redisClusterCommands.hrandfieldWithvalues(key, 2); //works fine!
Collection<KeyValue<String, String>> values2 = redisClusterCommands.hrandfieldWithvalues(key, 1); //throws exception

Expected behavior/code

no exception :)

Environment

  • Lettuce version(s): 6.3.2.RELEASE
  • Redis version: 7.4.2

Possible Solution

Additional context

Looks similar to #711 although that bug report indicates they ran into the error during an mget call.

I believe the bug is here in the multi method:
https://github.com/redis/lettuce/blob/main/src/main/java/io/lettuce/core/output/KeyValueListOutput.java#L77




If the count argument is one, and keys is null, the output field ends up as an immutable empty list and the UnsupportedOperationException is thrown when the code attempts to add an element to the list.

@tishun tishun added the type: bug A general bug label Jan 11, 2025
@tishun tishun added this to the 6.6.0.RELEASE milestone Jan 11, 2025
@tishun
Copy link
Collaborator

tishun commented Jan 11, 2025

Thanks for the report!

Yes you are more than certainly right and this seems like a bug in the KeyValueListOutput
The team will try to get this sorted out with the 6.6.0 release

@tishun tishun added the status: mre-available Minimal Reproducible Example is available label Jan 11, 2025
@tishun
Copy link
Collaborator

tishun commented Jan 11, 2025

MRE available here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: mre-available Minimal Reproducible Example is available type: bug A general bug
Projects
None yet
2 participants