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

Incorrect results due to hash key conflicts #7

Open
gpeddle-teal opened this issue Jul 23, 2020 · 3 comments
Open

Incorrect results due to hash key conflicts #7

gpeddle-teal opened this issue Jul 23, 2020 · 3 comments

Comments

@gpeddle-teal
Copy link

The hash keys are only 31 bit positive integers. From someone else's analysis I see that:

"Assuming a 32-bit hash and k=10,000 items, a collision will occur with a probablility of 1.2%. For 77,163 samples the probability becomes 50%!"

It does not appear that there's any code to compare the original keys and detect these conflicts. Even with a moderately sized cache errors go undetected.

I would suggest either a 64-bit hash or a mechanism for detecting the errors.

@ablewalmsley
Copy link

ablewalmsley commented Jul 23, 2020

one existing workaround for this would be to set hashCacheKeys to false in your config

@sebelga
Copy link
Owner

sebelga commented Jul 27, 2020

Hi @gpeddle-teal
Thanks for pointing this out! I don't have the bandwidth for the moment to make the change. If you want to open a PR and replace the hash function here https://github.com/sebelga/nsql-cache/blob/master/lib/utils.js#L28 that'd be awesome.
Cheers!

@Hardsix
Copy link

Hardsix commented Dec 6, 2021

You guys could at least make the option hashCacheKeys false as default, or refer to this in examples. One example has hashCacheKeys: true and the other example doesn't mention it. This leads people to think it is false by default.

This bit my company hard and caused a major prod issue due to cache key conflicts. I should've reviewed this dependency better but still.

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

No branches or pull requests

4 participants