Closed OsoianMarcel closed 2 months ago
Hi @OsoianMarcel, which node version are you using? Also, did you encounter this problem while using decorator?
I do experience the same issue. I am using the decorator and I have node v18.19.0
. Version 3.0.1
works perfectly but version 3.2.0
just throws almost the same error as op. I think the difference is that he is using the service while I am using the decorator
err: {
"type": "MurLockException",
"message": "Failed to acquire lock for key RafflePeriodicalCreationService:generateRafflesIfNeeded: No active store found",
"stack":
MurLockException: Failed to acquire lock for key RafflePeriodicalCreationService:generateRafflesIfNeeded: No active store found
at /Users/florinmunteanu/work/tron/apps/core/node_modules/murlock/lib/decorators/murlock.decorator.ts:86:11
at Generator.throw (<anonymous>)
at rejected (/Users/florinmunteanu/work/tron/apps/core/node_modules/murlock/dist/decorators/murlock.decorator.js:6:65)
"name": "MurLockException"
}
Hi @OsoianMarcel, which node version are you using? Also, did you encounter this problem while using decorator?
Node version: v20.11.0 I'm using the service, not decorator.
I'm experiencing the same issue with 3.1.0 or 3.2.0. I'm using version 3.1.0-beta.1, which works just fine.
However, the issue is related to this. The only way to have a store is by using the interceptor.
If the application uses the service directly or is not using the AsyncStorageInterceptor
interceptor, the store will not exist.
This approach was introduced to address this issue. However, it's a very specific scenario where the same application needs to lock the same context. Therefore, it probably should be applied only to those who have this requirement (manually), such as by adding a decorator to the endpoint or something similar.
I think maybe a solution could be to use the nestjs-cls again.
Since this issue is related to the context, this could be used on a decorator's "group".
Something like this:
export function MurLockWrapperExample(ms: number, name: string) {
return applyDecorators(
UseCls(),
MurLock(ms, name)
);
}
Hello @Scoup @powerofsoul @OsoianMarcel , I am very sorry that I could not solve the problem due to my health problems. I have released and tested a beta version for the solution, if you test it too, I can upgrade to the stable version.
@felanios I hope you're better. I have a lot of e2e tests on my application and mostly failed with this version, the same issue:
Unknown Error: Failed to acquire lock for key CacheService:updateUserReactions:b89e0d19-632b-48d3-97b3-3d873fbc964c:3fad9016-7790-4d2d-bace-068b86f0bf5f: No active store found
This is mostly a web socket project and doesn't use HTTP interceptors. I only use the decorator, like this:
@MurLock(500, 'reaction.widgetId', 'reaction.itemId', 'reaction.userId')
async updateReaction(reaction: Reaction) {
const key = this.getReactionKey(reaction);
await this.redis.set(key, JSON.stringify(reaction), 'EX', this.ttl);
}
@Scoup Thank you I'm better now. Yes you are right, Murlock is not compatible with non-HTTP clients. Normally with nestjs-cls package it support non-HTTP clients, but nestjs-cls also come up with a different dependency problem.
@Scoup Thank you I'm better now. Yes you are right, Murlock is not compatible with non-HTTP clients. Normally with nestjs-cls package it support non-HTTP clients, but nestjs-cls also come up with a different dependency problem.
What are the issues with nestjs-cls? The idea is to create a wrapper around some code and keep unique identifiers. Maybe we only need to think about where these wrappers will be, like in the interceptor and/or in the decorators.
@Scoup https://github.com/felanios/murlock/issues/18 This is the issue about nestjs-cls. With 3.0.0 also I switched to mount interceptor for non-http requests support and nestjs-cls perfectly support for this kind of clients.
Hey guys, sorry for late update. https://www.npmjs.com/package/murlock/v/3.3.0-beta.1 I just released new beta version for non-http clients support. I'll just keep it as a beta version for now.
Conflict with the AsyncLocalStorage (i think) #41
Great news! Thanks for the update!
Hey @Scoup, I released the stable version also(https://www.npmjs.com/package/murlock/v/3.3.0). There were no problems when I tested it, but I still can't be sure what people will encounter. If you encounter any problems, I would appreciate it if you update this issue.
Hey @Scoup, have you encountered any issues with the latest version? If not, I will close the issue.
Hey @Scoup, have you encountered any issues with the latest version? If not, I will close the issue.
@felanios, no issue is working fine, and all tests passed! Thanks for the update.
Calling the Murlock service -
await this.murLockService.lock(lockName, 5e3);
Throws this error:
The prev. version 3.0.1 worked just fine.