Skip to content

Malformed RESP can cause junk responses to the application which cannot be caught. #1172

Closed

Description

@stockholmux

In a malfunctioning Redis server (long story) partial or malformed RESP responses were being returned. While ioredis can detect these issues (message: ParserError: Protocol error, got ... as reply type byte. Please report this.) the response is still being returned back to the application via a callback or promise. This is most likely the same as #1166

Here is a test case to reproduce the bug with a mock server:

import Redis from "../../lib/redis";
import { expect } from "chai";
import MockServer from "../helpers/mock_server_delay";

const errorTrigger = 4;
let callCount = 0;

describe("mal-formed",  function () {
  it("should not return mal-formed resp", async function () {

    new MockServer(30000, (argv) => {
      if (argv[0] === "get") {
        // this will echo the key passed to GET, so GET A returns "A", GET B returns "B"
        callCount += 1;
        let out = `$${String(argv[1]).length}\r\n${String(argv[1])}\r\n`; 
        // until we get to the specified call count then it will return addtional mal-formed RESP       
        if (callCount === errorTrigger) {   
          // repeat the last command & lop off some control characters    
          out += out.slice(0,-3); 
        }
        return MockServer.raw(out);
      }
    });
    

    const redis = new Redis(30000);
    // loop through 'a' to 'g'
    let responses = '';
    try {
      for (let i = 97; i < 107; i += 1) {
        responses += await redis.get(String.fromCharCode(i));
      }
      expect(responses).to.equal('abcdefghij');
    } catch (e) {
      throw new Error(e);
    } 
  });
});

This results in the test not succeeding because responses was abcd$fghij not the expected abcdefghij. Similar issues persisted with callback style responses as well as promises.

I would expect that if a malformed response was detected this would never be returned to the application orthogonally to the error handling or response style.

Activity

  1. added a commit that references this issue on Nov 23, 2026
    77f88ee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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