Skip to content

Bug: nested transient scoped service instance is being reused within request context #15689

@stineslenea

Description

@stineslenea

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I have a request scoped service & controller, that both inject a transient service that itself also injects a transient service. I am observing that the nested service instance created is being reused for both instances of the first transient service.

Service (Request) injects Service (Transient, instance #1) injects NestedService (Transient, instance #1)
Controller (Request) injects Service (Transient, instance #2) injects NestedService (Transient, instance #1)

Minimum reproduction code

https://github.com/stineslenea/logger-transient-example

Steps to reproduce

npm i
npm run build
npm run start
call http://localhost:3000/test and check the log

Expected behavior

I expect both transient services get instances created for both controller and service.

NestJS version

11.1.6

Packages versions

{
  "dependencies": {
    "@nestjs/common": "11.1.6",
    "@nestjs/core": "11.1.6",
    "@nestjs/platform-express": "11.1.6",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.8.1"
  },
  "devDependencies": {
    "@nestjs/cli": "latest",
    "@nestjs/schematics": "latest",
    "@nestjs/testing": "latest",
    "@types/node": "^20.3.1",
    "typescript": "^5.1.3"
  }
}

Node.js version

20.12.2

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

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