Default RedisClient (RESP3 negotiated), pool maxTotal=1, Redis 8.10.3. A script stores redis.pcall results in a map and counter:b holds a non-integer:
EVAL "local out = {} for _, k in ipairs(KEYS) do out[k] = redis.pcall('INCR', k) end return {map=out}" 3 counter:a counter:b counter:c
<- %3 $9 counter:a :1 $9 counter:b -ERR value is not an integer or out of range $9 counter:c :1
eval threw JedisDataException: ERR value is not an integer or out of range
GET profile:alice -> counter:c
GET profile:bob threw ClassCastException: class java.lang.Long cannot be cast to class [B
GET profile:carol -> [email protected]
GET profile:dave -> [email protected]
processMapKeyValueReply calls process() for each key and value without catching JedisDataException, so it stops at the nested error and leaves the rest of the map on the socket. readProtocolWithCheckingBroken treats a JedisDataException as a fully parsed reply and does not mark the connection broken, so the pool hands it out again and every later reply on it is off by one, giving one caller another caller's data.
processMultiBulkReply already keeps a nested error as the element and carries on reading. The map path now does the same, so eval/fcall return the error as that entry's value, as they already do for the RESP2 array form of the same reply. RESP3 has been negotiated by default since 8.0, so this hits default RedisClient/RedisClusterClient setups whenever a script or function returns a map with an error inside.
ProtocolRepliesTest pinned the old throw for a map value; it now checks the copy like the array, set and push cases. New tests in ProtocolTest and ScriptingCommandsTest fail before the change (the latter on its RESP3 parameter) and pass after; release-notes entry added.
Note
Medium Risk
Fixes a serious pooled-connection reply misalignment bug; changes error handling for map/script replies that embed errors instead of failing the whole command.
Overview
Fixes a connection desync on RESP3 when a map reply includes a nested error (e.g. Lua {map=...} with redis.pcall failures). Parsing used to stop at the first JedisDataException, leave unread map bytes on the socket, and keep the connection in the pool—later commands could receive another caller's shifted replies.
processMapKeyValueReply now reads every key/value via processMapElement, which retains nested errors as map values (matching processMultiBulkReply). eval/fcall return the map instead of throwing for that case; callers should inspect values for JedisDataException.
Release notes, unit tests (ProtocolTest, ProtocolRepliesTest), and an integration test (evalMapWithPcallErrorKeepsConnectionInSync) cover the new behavior.
Reviewed by Cursor Bugbot for commit 046b022. Bugbot is set up for automated code reviews on this repo. Configure here.