Skip to content

Conversation

@hajekjiri
Copy link
Contributor

Fix race condition in class dependency resolution, which could otherwise lead to undefined or null injection. This is a followup to #15405 that fixes another case of this bug that was not taken care of in the previous PR. In this case specifically, the staticity of the dependency tree could be checked before all dependencies are loaded and the param / property Barrier is passed, resulting in a potentially wrong evaluation of the isTreeStatic property of the InstanceWrapper.

Closes #4873

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

A specific setup of transient-scoped and request-scoped providers with many global modules leads to null or undefined injection due to incorrect evaluation of the staticity of the dependency tree with a specific setup of request-scoped and transient-scoped providers with many global modules.

Issue Number: #4873

What is the new behavior?

The dependencies are injected correctly.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

I removed 2 test cases that test whether loadProvider() was called, because lookupComponentInImports() no longer calls it. To catch future regressions, I extended an existing integration test introduced in my previous PR regarding this issue (#15405).

The fix lies in the removal of a loadProvider() call, which is safe, because it is called almost immediately (along with the appropriate settlement signal) after the method returns and the param / property Barrier is passed (via resolveComponentHost()).

Fix race condition in class dependency resolution, which could otherwise
lead to undefined or null injection. This is a followup to nestjs#15405 that
fixes another case of this bug that was not taken care of in the
previous PR. In this case specifically, the staticity of the dependency
tree could be checked before all dependencies are loaded and the param /
property Barrier is passed, resulting in a potentially wrong evaluation
of the `isTreeStatic` property of the `InstanceWrapper`.

Closes nestjs#4873
@coveralls
Copy link

Pull Request Test Coverage Report for Build 8a9ca339-ab74-4090-839f-edf407cfaff7

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 12 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.1%) to 88.764%

Files with Coverage Reduction New Missed Lines %
packages/core/injector/injector.ts 12 79.25%
Totals Coverage Status
Change from base Build 52362f9b-3b1b-4350-80e5-95eab6af1468: -0.1%
Covered Lines: 7268
Relevant Lines: 8188

💛 - Coveralls

@kamilmysliwiec kamilmysliwiec merged commit 60b2ed4 into nestjs:master Aug 7, 2025
4 checks passed
@kamilmysliwiec
Copy link
Member

LGTM

@mareksuscak
Copy link

mareksuscak commented Sep 22, 2025

We use nest-commander and for some reason, this change broke injection of the Logger for us in one of the command providers. @kamilmysliwiec @hajekjiri is there any documentation for cases this fixes and cases this change breaks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global module provider injection issue

4 participants