Repository: nestjs/nest

Issue #7913: Sharing same @EventPattern across 2 handlers is broken if 2nd handler uses an interceptor
Created: 2021-08-22T15:00:19Z
Bug Report
Current behavior
Given two controller route handlers that subscribe to the same @EventPattern, both handlers are executed as expected.  However, if an interceptor is used on the 2nd handler, the interceptor is executed but the handler itself is never executed

Input Code

Reproduce: https://github.com/RoxKilly/nestjs-redis-troubleshoot/tree/issue-7913
export class AppController implements OnModuleInit {
  constructor(@Inject('REDIS_CLIENT') private redis: ClientRedis) {}

  onModuleInit(): any {
    this.redis.emit(eventPattern, 'NEW EVENT');
  }

  @EventPattern(eventPattern)
  handler1(data) {
    Logger.log(data, 'Handler 1');
  }

  /** This will not be triggered unless we disable the interceptor or remove the other handler */
  @EventPattern(eventPattern)
  @UseInterceptors(LoggingInterceptor)
  handler2(data) {
    Logger.log(data, 'Handler 2');
  }
}
Without Interceptor
Notice that both handler1 and handler2 receive and log the NEW EVENT

With Interceptor on 2nd handler
Notice the interceptor for handler2 is triggered, but handler2 never executes (it doesn't log the event)

Expected behavior

I expected both handlers to be triggered even if I use an interceptor on the 2nd handler.
Possible Solution

Removing the interceptor from the 2nd handler makes this go away but is not a practical workaround.
Environment

Nest version: 8.0.6

 
For Tooling issues:
- Node version: 16.4.0 
- Platform:  Windows

Others:

Duplicate issue #12091: [8.0.9] - Sharing same @EventPattern across 2 handlers is broken if 2nd handler uses an interceptor and the controller is request scoped
Created: 2023-07-20T15:45:00Z
Is there an existing issue for this?

 I have searched the existing issues

issue.
Current behavior
Given two controller route handlers that subscribe to the same @EventPattern, both handlers are executed as expected. However, if an interceptor is used on the 2nd handler and the controller is request scoped, the interceptor is executed but the handler itself is never executed
Related to this issue.
I forked the repository of this issue and upgraded Nestjs to version 8.0.9 which is supposed to have fixed this problem, but it persists if the controller is in scope request.
Minimum reproduction code
https://github.com/Dovakeidy/nestjs-redis-troubleshoot/tree/issue-7913
Steps to reproduce

yarn
yarn start:dev
Goto localhost:3000/ping

Expected behavior
I expected both handlers to be triggered even if I use an interceptor on the 2nd handler and the controller is request scoped.
Package

 I don't know. Or some 3rd-party package
 @nestjs/common
 @nestjs/core
 @nestjs/microservices
 @nestjs/platform-express
 @nestjs/platform-fastify
 @nestjs/platform-socket.io
 @nestjs/platform-ws
 @nestjs/testing
 @nestjs/websockets
 Other (see below)

Other package
No response
NestJS version
8.0.9
Packages versions
{
  "name": "nestjs-redis-test",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main"
  },
  "dependencies": {
    "@nestjs/common": "8.0.9",
    "@nestjs/core": "8.0.9",
    "@nestjs/microservices": "8.0.9",
    "@nestjs/platform-express": "8.0.9",
    "cache-manager": "3.4.4",
    "cache-manager-redis-store": "2.0.0",
    "redis": "3.1.2",
    "reflect-metadata": "0.1.13",
    "rimraf": "3.0.2",
    "rxjs": "7.2.0"
  },
  "devDependencies": {
    "@nestjs/cli": "8.1.1",
    "@nestjs/schematics": "8.0.2",
    "@types/cache-manager": "3.4.1",
    "@types/express": "4.17.12",
    "@types/node": "14.17.4",
    "prettier": "2.3.2",
    "supertest": "6.1.3",
    "ts-loader": "8.3.0",
    "ts-node": "9.1.1",
    "tsconfig-paths": "3.10.1",
    "typescript": "4.3.5"
  }
}
Node.js version
14.18.3
In which operating systems have you tested?

 macOS
 Windows
 Linux

Other
No response

Closing comment (2023-07-20T15:46:25Z): Related to #7913