Skip to content
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

Fix: Issue of synchronizing namespaced local memory caches #37

Merged
merged 4 commits into from
Oct 1, 2024

Conversation

gkachru
Copy link
Contributor

@gkachru gkachru commented Oct 1, 2024

Changes to namespaced local memory caches do not get pushed correctly.

When the CacheStack is namespaced, it creates a namespaced version of the l1 drivers, however does not create a new bus with the modified l1 driver. This change fixes that.

Added some test cases as well. Should fix #32

@Julien-R44
Copy link
Owner

Looks perfect!
Thanks a lot for taking the time to fix this issue

@Julien-R44 Julien-R44 merged commit f077d30 into Julien-R44:main Oct 1, 2024
4 checks passed
@wodCZ
Copy link

wodCZ commented Oct 3, 2024

@Julien-R44 could we get a release pretty please? 🙏 Wanted to try this fix, but I'm running into other issue when trying to install from main.

@Julien-R44
Copy link
Owner

Julien-R44 commented Oct 3, 2024

@wodCZ Yup sorry! Released with 1.0.0-beta.10

@wodCZ
Copy link

wodCZ commented Oct 4, 2024

Hmm. I might have misunderstood the goal of this PR, but I'm still having issues with namespace synchronization across multiple processes.

I've created a minimal reproduction: https://github.com/wodCZ/bentocache-bus-repro

@Julien-R44
Copy link
Owner

Thanks for the repro dude !

There is indeed an issue going on. Let me check that

@gkachru
Copy link
Contributor Author

gkachru commented Oct 4, 2024

Different issue with BinaryEncoding not handling the Clear message correctly. #38 should fix it.

@Julien-R44
Copy link
Owner

Released with beta.11

l2Driver: this.l2?.namespace(namespace),
busDriver: this.#busDriver,
busOptions: this.#busOptions,
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gkachru I believe, there should be 4th argument passed with this.bus, otherwise a new bus is created every time any namespace is accessed.

This can be seen in https://github.com/wodCZ/bentocache-bus-repro, if you run the main.js, you see the following error after 10 logs:

(node:70661) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 reconnecting listeners added to [Commander]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit
    at genericNodeError (node:internal/errors:983:15)
    at wrappedFn (node:internal/errors:537:14)
    at _addListener (node:events:593:17)
    at EventEmitter.addListener (node:events:611:10)
    at RedisTransport.onReconnect (file:///Users/wod/sites/bentotest/node_modules/@boringnode/bus/build/src/transports/redis.js:68:26)
    at new Bus (file:///Users/wod/sites/bentotest/node_modules/@boringnode/bus/build/src/bus.js:28:38)
    at new Bus (file:///Users/wod/sites/bentotest/node_modules/bentocache/build/index.js:588:17)
    at #createBus (file:///Users/wod/sites/bentotest/node_modules/bentocache/build/index.js:1098:20)
    at new _CacheStack (file:///Users/wod/sites/bentotest/node_modules/bentocache/build/index.js:1076:31)
    at _CacheStack.namespace (file:///Users/wod/sites/bentotest/node_modules/bentocache/build/index.js:1102:12)

Thanks for the amazing work otherwise 🙏

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS: just checked adding the 4th arg locally and the memory leak warning is gone, while both namespace sync issues remain fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bus does indeed need to be created every time, as you need to pass in the new namespace localcache instance. It is however generally a memory intensive way as both CacheStack and bus get created.

The event emitter warning can be eliminated by setting up something like const bcProducts = bento.namespace('products') and then using bcProducts.set etc from then on. However, still you would have as many CacheStack and bus instances as there are namespaces, plus one for the original bento instance.

The reason why .clear() still works as you pass in the original bus, is because all buses are listening to the same queue name! So the clear message is received by every instance of the bus, both the namespaced and non-namespaced one, which will clear all items everywhere!

Have noticed this, and I am working on this issue as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added PR #39 to address the excessive messages by namespacing the bus channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

With a bus, clearing a namespace will clear the entire cache
3 participants