Skip to content

A custom deserializer error crashes the TCP, Redis, MQTT and RMQ clients #17994

Closed

Description

@johnnyhuirilef

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Hi! 👋 This is the sibling of #17958, which was about ClientNats.

I give a client a custom deserializer that expects a certain reply shape:

ClientsModule.register([
  {
    name: 'ORDERS',
    transport: Transport.REDIS,
    options: {
      deserializer: {
        deserialize: (value) => ({ id: value.meta.id, response: value.body }),
      },
    },
  },
]);

When a reply does not match that shape, the deserializer throws. The client then crashes the whole process with exit code 1:

TypeError: Cannot read properties of undefined (reading 'id')

This happens in ClientTCP, ClientRedis, ClientMqtt and ClientRMQ. Each client awaits the deserializer inside a listener that nobody awaits, so the rejection is unhandled. I also tried TCP with an unhandledRejection handler. The process stays up, but the request never settles.

The default deserializer never throws, so only a custom deserializer triggers this. On Redis and MQTT, the reply topic is shared. So any publisher on that topic can send a reply that crashes the client.

Minimum reproduction code

https://github.com/johnnyhuirilef/nestjs-repros/tree/main/client-custom-deserializer-crash

Steps to reproduce

The README lists the docker run commands for Redis, Mosquitto and RabbitMQ. TCP needs no broker.

  1. npm install
  2. npm run repro

The script runs each client in its own child process. A plain responder answers once with a reply that the deserializer rejects, and once with a valid reply. Here is a shortened copy of the output:

=== TCP: reply the deserializer rejects ===
  outcome:     crashed (process exit code 1)
  stderr line: TypeError: Cannot read properties of undefined (reading 'id')

=== REDIS: reply the deserializer rejects ===
  ... same, outcome: crashed (process exit code 1)

=== MQTT: reply the deserializer rejects ===
  ... same, outcome: crashed (process exit code 1)

=== RMQ: reply the deserializer rejects ===
  outcome:     crashed (process exit code 1)

RESULT: BUG: 4 of 8 cases did not end as expected (a crashed client exits with code 1).

The four valid replies resolve with "ok".

Expected behavior

A deserializer error does not crash the process. When the client knows which request the reply belongs to, the request fails with the error, as #17959 did for ClientNats.

NestJS version

12.1.2

Packages versions

{
  "@nestjs/common": "12.1.2",
  "@nestjs/core": "12.1.2",
  "@nestjs/microservices": "12.1.2",
  "ioredis": "6.0.0",
  "mqtt": "5.16.0",
  "amqplib": "2.2.0",
  "amqp-connection-manager": "5.0.0"
}

Node.js version

24.19.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

The listeners are ClientTCP.handleResponse(), the response callbacks of ClientRedis and ClientMqtt, and ClientRMQ.handleMessage(). None of them catches an error from deserialize().

I have a fix ready and I can open a PR.

Activity

  1. added a commit that references this issue on Oct 8, 2026
    d6d080d
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

    needs triageThis issue has not been looked into

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions