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

Dangerous shared objects on cache miss #103

Closed
wants to merge 6 commits into from

Conversation

toto-castaldi
Copy link

No description provided.

@BryanDonovan
Copy link
Collaborator

Hi, thanks for this. I'm not sure I understand the need to clone though.

@toto-castaldi
Copy link
Author

We had this situation :
two clients calling the same server at the same time with a cache miss. If one of the server logic modifies the cached data before returning it to the client also the second will found that change in the data

@BryanDonovan
Copy link
Collaborator

Seems like the client should do the clone operation since the cost of doing the clone in the cache manager might not be worth it for most people's situations.

@toto-castaldi
Copy link
Author

Can be configurable in some way in order to maintain performance but my expected behavior is that I should not worry of other processes.
I'd say that this issue is only in the "wrap" section of the library, in the pure GET and SET this issue does not come up. So if is an optimization of the "wrap" should work.

@BryanDonovan
Copy link
Collaborator

I didn't think you could modify an object across processes. Are these clients running in the same process? In any case, it's possible to have multiple clients in the same process requesting the same data at the same time, so I'm ok with doing this if you make it configurable.

@@ -1,3 +1,13 @@
const deepmerge = require('deepmerge');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you use var, etc. here instead of ES6 syntax?

package.json Outdated
@@ -21,6 +21,7 @@
"license": "MIT",
"dependencies": {
"async": "1.5.2",
"deepmerge": "^1.5.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please pin this version to exactly 1.5.0. I know it's a debatable choice :)

gall0ws and others added 3 commits August 7, 2017 10:15
…ay#103

* added configurable option safeClone
* converted code to ES5
* fixed package.json

TODO:

- missing documentation about args.safeClone & options.safeClone (grep -n FILLME lib/*)
@coveralls
Copy link

coveralls commented Aug 7, 2017

Coverage Status

Coverage decreased (-1.4%) to 97.902% when pulling 714e9ac on Skillbill:master into dc3924c on BryanDonovan:master.

@ankopainting
Copy link

We were bitten badly by this bug today.

eg.

let a = await myCache.wrap("string", () => {return {name: "frank", age: 6}});
console.log(a);
a.name = "bob"

let b = await myCache.wrap("string", () => {return {name: "frank", age: 6}});
console.log(b);

should return
{name: "frank", age: 6}
{name: "frank", age: 6}

before this change it returned
{name: "frank", age: 6}
{name: "bob", age: 6}

Please merge and release! :)

@BryanDonovan
Copy link
Collaborator

I'm looking into this now.

@BryanDonovan
Copy link
Collaborator

I didn't merge this before because it has a bug and no tests. I'm fixing the bug and adding tests now.

@BryanDonovan
Copy link
Collaborator

This is fixed in version 2.10.2

The issue was in the memory store only, so that's where I added the fix, which is to clone the object before setting it in the memory cache. See 84901cc

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.

None yet

5 participants