-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Durable providers are unable to recover from errors being thrown #13953
Comments
here's a minimum reproduction of this: https://gitlab.com/micalevisk/nestjs-issue-11664 |
hope this gets some visibility soon, it is kind of a major bug indeed. @micalevisk which versione of nestjs are you using? i havent tried the latest yet, dont know if the bug was perhaps fixed there (i am on 10.1 i guess) |
btw, i have tested the patch in this PR: https://github.com/nestjs/nest/pull/11666/files and it seems to work, although it never made it to upstream ... if you know how to use use patch-package (https://dev.to/zhnedyalkow/the-easiest-way-to-patch-your-npm-package-4ece), you only need this patch file and durable providers will be decached on errors: @nestjs+core+10.3.3.patchdiff --git a/node_modules/@nestjs/core/injector/injector.js b/node_modules/@nestjs/core/injector/injector.js
index 53b1d5f..47f5741 100644
--- a/node_modules/@nestjs/core/injector/injector.js
+++ b/node_modules/@nestjs/core/injector/injector.js
@@ -70,6 +70,12 @@ class Injector {
await this.resolveConstructorParams(wrapper, moduleRef, inject, callback, contextId, wrapper, inquirer);
}
catch (err) {
+ // https://github.com/nestjs/nest/pull/11666/files
+ console.error("[@nestjs/core/injector.js] - error on init of", contextId, err)
+ wrapper.removeInstanceByContextId(
+ this.getContextId(contextId, wrapper),
+ inquirerId,
+ );
settlementSignal.error(err);
throw err;
}
diff --git a/node_modules/@nestjs/core/injector/instance-wrapper.js b/node_modules/@nestjs/core/injector/instance-wrapper.js
index 2f15b02..5bb87f1 100644
--- a/node_modules/@nestjs/core/injector/instance-wrapper.js
+++ b/node_modules/@nestjs/core/injector/instance-wrapper.js
@@ -75,6 +75,24 @@ class InstanceWrapper {
}
collection.set(contextId, value);
}
+ // https://github.com/nestjs/nest/pull/11666/files
+ removeInstanceByContextId(contextId, inquirerId) {
+ console.error("[@nestjs/core/instance-wrapper.js] - removing context", contextId, inquirerId)
+ if (this.scope === common_1.Scope.TRANSIENT && inquirerId) {
+ return this.removeInstanceByInquirerId(contextId, inquirerId);
+ }
+
+ this.values.delete(contextId);
+ }
+
+ removeInstanceByInquirerId(contextId, inquirerId) {
+ let collection = this.transientMap.get(inquirerId);
+ if (!collection) {
+ return;
+ }
+
+ collection.delete(contextId);
+ }
addCtorMetadata(index, wrapper) {
if (!this[exports.INSTANCE_METADATA_SYMBOL].dependencies) {
this[exports.INSTANCE_METADATA_SYMBOL].dependencies = [];
|
Let's track this here #14133 |
Is there an existing issue for this?
Current behavior
the issue is described here and it is still relevant: #11664
Minimum reproduction code
check here: #11664
Steps to reproduce
No response
Expected behavior
durable provider should be decached and retried next time.
it would be nice if this is the default behavior even after the creation of the provider, i.e. in case of exceptions along its life
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 package
No response
NestJS version
10.1.3
Packages versions
Node.js version
16
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: