Skip to content

Wrapper CommandOutputs don't forward all callbacks, breaking RESP3 replies in transactions and on pub/sub connections #3937

Closed

Description

@a-TODO-rov

Problem

Some CommandOutput implementations don't build a result themselves. They wrap the output of another command and pass the decoder's callbacks on to it:

  • MultiOutput routes each element of an EXEC reply to the output of the queued command it belongs to.
  • ReplayOutput records a reply on a pub/sub connection and replays it into the command's output.

CommandOutput has 14 callbacks: set(ByteBuffer), setSingle, setBigNumber, set(long), set(double),
set(boolean), setError(ByteBuffer), setError(String), complete, multi, multiArray, multiPush, multiMap and multiSet. A wrapper only works correctly if it forwards every one of them unchanged. Nothing forces it to: a callback the wrapper doesn't override silently falls back to the default in CommandOutput. Depending on the callback, that default either throws or converts the call into a different one.

Several RESP3 callbacks were added in 6.0, and the wrappers were only partly updated, so some of them are missing today.

Symptoms

1. RESP3 booleans inside a transaction throw

MultiOutput has no set(boolean). The default throws UnsupportedOperationException, so any command that returns a RESP3 boolean fails inside MULTI/EXEC:

redis.multi();
redis.bfAdd("bf", "x");
redis.exec(); // fails: MultiOutput does not support set(boolean)

addressed in #3932

2. RESP3 maps and sets inside a transaction become lists

MultiOutput has no multiMap or multiSet. The default turns multiMap(n) into multi(2n), and MultiOutput forwards only that, so the command's output never learns that a map was sent:

String script = "return {map={name='lettuce'}}"; // RESP3 map reply

redis.eval(script, ScriptOutputType.OBJECT);  // {name=lettuce}  (LinkedHashMap)

redis.multi();
redis.eval(script, ScriptOutputType.OBJECT);
redis.exec().get(0);                          // [name, lettuce]  (ArrayList)

No error is raised; the result just has a different type. This affects outputs that build something different for a
map than for an array, mainly ObjectOutput (FUNCTION LIST, CLUSTER LINKS, EVAL/EVALSHA/FCALL with ScriptOutputType.OBJECT, dispatch with ObjectOutput). For example, functionList() inside a transaction returns each library as a flat list of keys and values instead of a Map.

3. The same gaps on pub/sub connections

ReplayOutput overrides only set(ByteBuffer), set(long), set(double), setError, complete and multi:

  • No set(boolean): a RESP3 boolean reply to a command on a pub/sub connection fails with
    UnsupportedOperationException.
  • No multiMap or multiSet: they're recorded as plain multi(), so map and set replies on a pub/sub connection should arrive at the command's output as lists, the same way as in symptom 2. (From reading the code; not reproduced.)

RESP2 is not affected by any of these, because RESP2 has no boolean, map or set types.

Proposed direction

Fixing the missing overrides one by one solves today's symptoms, but the next callback added to CommandOutput would reopen the problem. The fix should make complete forwarding the default:

  • Introduce a common base class for wrapper outputs that forwards every callback to a target output, and have MultiOutput and ReplayOutput extend it. MultiOutput then only overrides what it handles differently (the EXEC reply header and complete), and a new callback added to the base class is forwarded automatically.
  • Alternatively, at minimum, add a unit test that lists CommandOutput's public callbacks and fails if a wrapper output doesn't override one of them.

TransformingOutput already forwards every callback by hand and could move to the same base class.

Note that fixing symptom 2 changes visible behavior: inside a transaction on RESP3, ObjectOutput-based commands will eturn a Map where they return a List today. That matches the result outside a transaction, but should be called out in the release notes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions