liaoliaots / nestjs-redis

Redis module for Nest framework (node.js). Support node-redis & ioredis.
MIT License
392 stars 71 forks source link

fix: application shutdown #536

Closed DecathectZero closed 2 months ago

DecathectZero commented 1 year ago

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

What is the current behavior?

Currently when my app has enableShutdownHooks it will fail every time because of:

.../node_modules/@nestjs/core/injector/instance-links-host.js:24
            throw new unknown_element_exception_1.UnknownElementException(this.getInstanceNameByToken(token));
                  ^

Error: Nest could not find Symbol() element (this provider does not exist in the current context)
    at InstanceLinksHost.get (.../node_modules/@nestjs/core/injector/instance-links-host.js:24:19)
    at Object.find (.../node_modules/@nestjs/core/injector/abstract-instance-resolver.js:8:60)
    at Object.get (.../node_modules/@nestjs/core/injector/module.js:399:29)
    at RedisModule2.onApplicationShutdown (.../node_modules/@liaoliaots/nestjs-redis/dist/redis/redis.module.js:68:48)
    at callAppShutdownHook (.../node_modules/@nestjs/core/hooks/on-app-shutdown.hook.js:51:35)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at NestApplication.callShutdownHook (.../node_modules/@nestjs/core/nest-application-context.js:254:13)
    at process.cleanup (.../node_modules/@nestjs/core/nest-application-context.js:191:17)

Digging through the NestJS source code and logging all the issues, this: https://github.com/nestjs/nest/blob/master/packages/core/injector/module.ts#L611-L615 the self.id NEVER matches up with the ID of whatever this.moduleRef.get<RedisModuleOptions>(REDIS_MERGED_OPTIONS) or this.moduleRef.get<RedisClients>(REDIS_CLIENTS) is.

This check always fails: https://github.com/nestjs/nest/blob/master/packages/core/injector/instance-links-host.ts#L44-L46

This PR also address and fixes this issue: https://github.com/liaoliaots/nestjs-redis/issues/335

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

Other information

liaoliaots commented 2 months ago

Please check out the new version: version 10 of @liaoliaots/nestjs-redis.