Repository navigation
fix: decode RESP3 attribute replies instead of failing the connection - #2213
Conversation
ioredis defaults to protocol 3, but the decoder has no case for the RESP3 attribute type (`|`, 124). A single attribute reply therefore ends the connection: the decoder throws "Unknown RESP type 124", DataHandler turns that into a fatal protocol error, and every command in flight on the socket is dropped. `DEBUG PROTOCOL attrib` reproduces it, and the public module API (`RedisModule_ReplyWithAttribute`) lets any module produce one. An attribute is metadata for the reply behind it, not a reply of its own, so at the top level the attribute map is consumed without invoking a callback - the main loop then decodes the real reply that follows - and nested in an array, set or map the element after the attribute takes its place. The contents are discarded, which the spec allows and which is all the connection needs; surfacing them to callers would be a separate API change.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 5e056a9. Configure here.
The first commit resumed every attributed element through #decodeNestedType,
so a map key behind an attribute followed typeMapping instead of being coerced
to a string like any other key. With blob strings mapped to Buffer - what both
of DataHandler's presets do - that key came back as a Buffer from a Map, so
map.get("foo") missed it, and in the object path it walked past the
`__proto__` guard in #decodeMapAsObject, whose own-property check compares
against a string. A reply with an attributed `__proto__` key and an object
value then changed the decoded object's prototype.
Pass the decoder for the position the attribute was found in, so a key resumes
through #decodeMapKey and everything else through #decodeNestedType.
|
Bugbot was right about the map keys, fixed in 3e7c9e6. Resuming through Now the attribute resumes with the decoder for the position it was found in: |
|
@Develop-KIM Thanks for the PR! I'll have a look. |
There was a problem hiding this comment.
Thanks @Develop-KIM, and thanks for the careful work here.
To be upfront: I don't think this is a real-world issue. In practice the only things that send RESP3 attributes are DEBUG PROTOCOL attrib and Redis's own test module. I couldn't find any public module that calls RedisModule_ReplyWithAttribute, and nobody has reported this from production. I'm still happy to merge it as a small spec-conformance fix, because a RESP3 client shouldn't drop the connection on a valid RESP3 type.
Because of that, I'd like the change to look as small as it really is. A large test block and long comments make it look like an important feature area, and that misleads whoever works on the decoder next. Could you:
- Trim the Attribute tests to one per decoder path. The harness already runs every chunk split, so these three cover everything the patch touches:
DEBUG PROTOCOL attrib(top level)on an array element(nested)on a __proto__ map keywith Buffer mapping (map-key path and prototype guard)
- Cut the decoder comments to one line per
case, e.g.// RESP3 attribute: consume and discard, then decode the decorated value.
Happy to approve once that's in.
Three cases cover what the patch touches - top level, nested, and the map-key path with Buffer mapping - and the decoder comments are down to one line per case.
|
Both done in a9f096b — the three cases you listed are what's left, and each decoder I re-ran the trimmed set against an unpatched decoder to make sure nothing lost coverage: all three go red without the fix, and the |
# [6.1.0-beta.1](v6.0.0...v6.1.0-beta.1) (2026-10-12) ### Bug Fixes * accept field arrays in hmget/hmgetBuffer types ([#2167](#2167)) ([c0cd66c](c0cd66c)) * align auto-pipeline callbacks for dynamic commands ([#2180](#2180)) ([7479cab](7479cab)) * clean up Sentinel failover subscriptions after quit ([#2198](#2198)) ([727edfa](727edfa)) * cluster stuck in close ([#2217](#2217)) ([a5fad1d](a5fad1d)) * **cluster:** bucket autopipelined MSET objects by their first key ([#2207](#2207)) ([b4e3237](b4e3237)) * **cluster:** hash autopipelined Buffer keys by their bytes ([#2208](#2208)) ([a8378bd](a8378bd)), closes [Command#getSlot](https://github.com/Command/issues/getSlot) * **cluster:** match Buffer shard channels when unsubscribing ([#2203](#2203)) ([d997d01](d997d01)) * **cluster:** support zero-argument sunsubscribe with sharded subscribers ([#2137](#2137)) ([13ff050](13ff050)), closes [#2133](#2133) * **cluster:** vendor cluster-key-slot to fix empty hash tag slot bug ([#2172](#2172)) ([b479b76](b479b76)) * decode integer replies up to MAX_SAFE_INTEGER exactly ([#2164](#2164)) ([28940b5](28940b5)) * decode RESP3 attribute replies instead of failing the connection ([#2213](#2213)) ([6a8cb3e](6a8cb3e)), closes [#decodeNestedType](https://github.com/redis/ioredis/issues/decodeNestedType) [#decodeMapAsObject](https://github.com/redis/ioredis/issues/decodeMapAsObject) [#decodeMapKey](https://github.com/redis/ioredis/issues/decodeMapKey) * decode RESP3 doubles with Number ([#2150](#2150)) ([6fb5a10](6fb5a10)) * handle rejections from auto-resubscribe and select on reconnect ([#2187](#2187)) ([de2fbdf](de2fbdf)) * inherit connectTimeout for cluster subscribers ([#2220](#2220)) ([db57c2d](db57c2d)) * keep String.prototype in fast mode after defining VerbatimString ([#2206](#2206)) ([90e1261](90e1261)) * keep subscriber mode while other channel kinds remain subscribed ([#2196](#2196)) ([eb97beb](eb97beb)) * keep the exec error out of its own previousErrors ([#2218](#2218)) ([2c602cf](2c602cf)) * preserve empty keys and match patterns in scan streams ([#2199](#2199)) ([b169c3a](b169c3a)) * reject unfulfilled commands dropped on reconnect ([#2194](#2194)) ([d95d05a](d95d05a)), closes [#2193](#2193) * reset retry attempts when connect() is called after giving up ([#2204](#2204)) ([b597303](b597303)), closes [#1463](#1463) * **types:** accept documented TLS profile options ([#2195](#2195)) ([56a7fb8](56a7fb8)), closes [#1626](#1626) * **types:** add event overloads to Cluster interface ([#2201](#2201)) ([3996eaf](3996eaf)), closes [#2191](#2191) * **types:** add smessage and smessageBuffer event overloads ([#2191](#2191)) ([ee48f4c](ee48f4c)), closes [#2190](#2190) * **types:** allow number for zrange stop argument ([#2163](#2163)) ([932f4c2](932f4c2)) ### Features * bless commands ([#2209](#2209)) ([9181ee0](9181ee0)) * **cluster:** allow configuring node role for Pub/Sub subscriber ([#2176](#2176)) ([6b9130c](6b9130c)) * smart client handoffs ([#2165](#2165)) ([d8ae3cb](d8ae3cb))
# [6.1.0-beta.1](v6.0.0...v6.1.0-beta.1) (2026-10-12) ### Bug Fixes * accept field arrays in hmget/hmgetBuffer types ([#2167](#2167)) ([c0cd66c](c0cd66c)) * align auto-pipeline callbacks for dynamic commands ([#2180](#2180)) ([7479cab](7479cab)) * clean up Sentinel failover subscriptions after quit ([#2198](#2198)) ([727edfa](727edfa)) * cluster stuck in close ([#2217](#2217)) ([a5fad1d](a5fad1d)) * **cluster:** bucket autopipelined MSET objects by their first key ([#2207](#2207)) ([b4e3237](b4e3237)) * **cluster:** hash autopipelined Buffer keys by their bytes ([#2208](#2208)) ([a8378bd](a8378bd)), closes [Command#getSlot](https://github.com/Command/issues/getSlot) * **cluster:** match Buffer shard channels when unsubscribing ([#2203](#2203)) ([d997d01](d997d01)) * **cluster:** support zero-argument sunsubscribe with sharded subscribers ([#2137](#2137)) ([13ff050](13ff050)), closes [#2133](#2133) * **cluster:** vendor cluster-key-slot to fix empty hash tag slot bug ([#2172](#2172)) ([b479b76](b479b76)) * decode integer replies up to MAX_SAFE_INTEGER exactly ([#2164](#2164)) ([28940b5](28940b5)) * decode RESP3 attribute replies instead of failing the connection ([#2213](#2213)) ([6a8cb3e](6a8cb3e)), closes [#decodeNestedType](https://github.com/redis/ioredis/issues/decodeNestedType) [#decodeMapAsObject](https://github.com/redis/ioredis/issues/decodeMapAsObject) [#decodeMapKey](https://github.com/redis/ioredis/issues/decodeMapKey) * decode RESP3 doubles with Number ([#2150](#2150)) ([6fb5a10](6fb5a10)) * handle rejections from auto-resubscribe and select on reconnect ([#2187](#2187)) ([de2fbdf](de2fbdf)) * inherit connectTimeout for cluster subscribers ([#2220](#2220)) ([db57c2d](db57c2d)) * keep String.prototype in fast mode after defining VerbatimString ([#2206](#2206)) ([90e1261](90e1261)) * keep subscriber mode while other channel kinds remain subscribed ([#2196](#2196)) ([eb97beb](eb97beb)) * keep the exec error out of its own previousErrors ([#2218](#2218)) ([2c602cf](2c602cf)) * preserve empty keys and match patterns in scan streams ([#2199](#2199)) ([b169c3a](b169c3a)) * reject unfulfilled commands dropped on reconnect ([#2194](#2194)) ([d95d05a](d95d05a)), closes [#2193](#2193) * reset retry attempts when connect() is called after giving up ([#2204](#2204)) ([b597303](b597303)), closes [#1463](#1463) * **types:** accept documented TLS profile options ([#2195](#2195)) ([56a7fb8](56a7fb8)), closes [#1626](#1626) * **types:** add event overloads to Cluster interface ([#2201](#2201)) ([3996eaf](3996eaf)), closes [#2191](#2191) * **types:** add smessage and smessageBuffer event overloads ([#2191](#2191)) ([ee48f4c](ee48f4c)), closes [#2190](#2190) * **types:** allow number for zrange stop argument ([#2163](#2163)) ([932f4c2](932f4c2)) ### Features * bless commands ([#2209](#2209)) ([9181ee0](9181ee0)) * **cluster:** allow configuring node role for Pub/Sub subscriber ([#2176](#2176)) ([6b9130c](6b9130c)) * smart client handoffs ([#2165](#2165)) ([d8ae3cb](d8ae3cb))
# [6.1.0-beta.1](v6.0.0...v6.1.0-beta.1) (2026-10-12) ### Bug Fixes * accept field arrays in hmget/hmgetBuffer types ([#2167](#2167)) ([c0cd66c](c0cd66c)) * align auto-pipeline callbacks for dynamic commands ([#2180](#2180)) ([7479cab](7479cab)) * clean up Sentinel failover subscriptions after quit ([#2198](#2198)) ([727edfa](727edfa)) * cluster stuck in close ([#2217](#2217)) ([a5fad1d](a5fad1d)) * **cluster:** bucket autopipelined MSET objects by their first key ([#2207](#2207)) ([b4e3237](b4e3237)) * **cluster:** hash autopipelined Buffer keys by their bytes ([#2208](#2208)) ([a8378bd](a8378bd)), closes [Command#getSlot](https://github.com/Command/issues/getSlot) * **cluster:** match Buffer shard channels when unsubscribing ([#2203](#2203)) ([d997d01](d997d01)) * **cluster:** support zero-argument sunsubscribe with sharded subscribers ([#2137](#2137)) ([13ff050](13ff050)), closes [#2133](#2133) * **cluster:** vendor cluster-key-slot to fix empty hash tag slot bug ([#2172](#2172)) ([b479b76](b479b76)) * decode integer replies up to MAX_SAFE_INTEGER exactly ([#2164](#2164)) ([28940b5](28940b5)) * decode RESP3 attribute replies instead of failing the connection ([#2213](#2213)) ([6a8cb3e](6a8cb3e)), closes [#decodeNestedType](https://github.com/redis/ioredis/issues/decodeNestedType) [#decodeMapAsObject](https://github.com/redis/ioredis/issues/decodeMapAsObject) [#decodeMapKey](https://github.com/redis/ioredis/issues/decodeMapKey) * decode RESP3 doubles with Number ([#2150](#2150)) ([6fb5a10](6fb5a10)) * handle rejections from auto-resubscribe and select on reconnect ([#2187](#2187)) ([de2fbdf](de2fbdf)) * inherit connectTimeout for cluster subscribers ([#2220](#2220)) ([db57c2d](db57c2d)) * keep String.prototype in fast mode after defining VerbatimString ([#2206](#2206)) ([90e1261](90e1261)) * keep subscriber mode while other channel kinds remain subscribed ([#2196](#2196)) ([eb97beb](eb97beb)) * keep the exec error out of its own previousErrors ([#2218](#2218)) ([2c602cf](2c602cf)) * preserve empty keys and match patterns in scan streams ([#2199](#2199)) ([b169c3a](b169c3a)) * reject unfulfilled commands dropped on reconnect ([#2194](#2194)) ([d95d05a](d95d05a)), closes [#2193](#2193) * reset retry attempts when connect() is called after giving up ([#2204](#2204)) ([b597303](b597303)), closes [#1463](#1463) * **types:** accept documented TLS profile options ([#2195](#2195)) ([56a7fb8](56a7fb8)), closes [#1626](#1626) * **types:** add event overloads to Cluster interface ([#2201](#2201)) ([3996eaf](3996eaf)), closes [#2191](#2191) * **types:** add smessage and smessageBuffer event overloads ([#2191](#2191)) ([ee48f4c](ee48f4c)), closes [#2190](#2190) * **types:** allow number for zrange stop argument ([#2163](#2163)) ([932f4c2](932f4c2)) ### Features * bless commands ([#2209](#2209)) ([9181ee0](9181ee0)) * **cluster:** allow configuring node role for Pub/Sub subscriber ([#2176](#2176)) ([6b9130c](6b9130c)) * smart client handoffs ([#2165](#2165)) ([d8ae3cb](d8ae3cb))
|
🎉 This PR is included in version 6.1.0-beta.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |

Fixes #2212.
ioredis defaults to
protocol: 3, but the decoder has no case for the RESP3 attribute type (|, 124), so one attribute reply ends the connection: the decoder throwsUnknown RESP type 124 "|",DataHandlertreats it as a fatal protocol error, and everything in flight on that socket is dropped.DEBUG PROTOCOL attribreproduces it;RedisModule_ReplyWithAttributeis public, so a module can produce one in normal use.An attribute is metadata for the reply behind it rather than a reply of its own, so:
#decodeTypeValuereturns without invoking a callback, which leaves the main loop to decode the real reply that follows. Nothing extra reachesonReply, so the command queue stays aligned.#decodeAttribute/#continueDecodeAttributeso it still resumes correctly when a chunk ends in the middle of an attribute.The contents are discarded. The spec allows ignoring them and this keeps the change to the parse-and-skip the connection needs; surfacing them to callers would be an API decision for a separate change.
Tests
test/unit/resp/decoder.tsgains anAttributeblock: the exactDEBUG PROTOCOL attribwire format, an empty attribute, two in a row, before an error, before a push, on an array element, on a nested array element, on a map key and on a map value, on aSetelement, and one whose own value is a map. The existing harness runs every case as a single chunk, byte by byte, and split at each byte boundary, so the resumable paths are covered — 33 of those assertions fail without the decoder change.Verified against Redis 8.8.0:
npm run test:jsis green (2684 passing), as arenpm run build,npx tsdandnpm run lint. End to end,debug protocol attribnow returnsSome real reply following the attributeand the connection stays up. The cluster suite needs the 3000-3005 nodes, which I couldn't start locally; its results are identical with and without this change.This was written with AI assistance; the behaviour and the tests are ones I verified myself.
Note
Medium Risk
Touches core RESP parsing and reply dispatch; behavior change is scoped to skipping metadata, but incorrect attribute handling could misalign replies or break streaming decode paths.
Overview
Fixes fatal protocol errors when Redis sends RESP3 attribute (
|) replies on the default RESP3 connection—previously the decoder threw on type 124 and the socket was torn down.The decoder now recognizes
ATTRIBUTE, parses the attribute payload as a map, and discards it (not exposed toonReply). At the top level, only the following real reply is delivered so the command queue stays aligned. Nested (arrays, sets, map keys/values), the attribute is skipped and the next value occupies that slot, with#decodeAttribute/#continueDecodeAttributepreserving chunk-boundary resume behavior. Map keys still go through the string key path after an attribute (including__proto__handling).Unit tests cover
DEBUG PROTOCOL attribwire format, attributes on array elements, and on a__proto__map key.Reviewed by Cursor Bugbot for commit a9f096b. Bugbot is set up for automated code reviews on this repo. Configure here.