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
Increment does not appear to be atomic #8772
Comments
Thanks for opening this issue!
|
Could you add a test case with that example that you already posted? |
I will have to examinate if I am doing anything special on my side. The following test works: fit('regression test for #8772 (increment should be atomic))', async () => {
Parse.Object.disableSingleInstance();
Parse.Cloud.beforeSave('Parent', (req) => {});
Parse.Cloud.beforeSave('Child', async (req) => {
await req.object.get("parent").increment("num_child").save(null, {useMasterKey:true})
});
let parent = await new Parse.Object('Parent').save(null, {useMasterKey:true});
const child = () => new Parse.Object('Child').set("parent",parent).save();
// add synchronously
await child()
await child()
parent = await parent.fetch();
expect(parent.get('num_child')).toBe(2);
// add asynchronously
await Promise.all(Array.from({length: 40}, () => child()))
parent = await parent.fetch();
expect(parent.get('num_child')).toBe(42); |
I's be surprised if no atomic test already exists. If there really is none we can add your test in any case. Could you open a PR? |
Actually I can't find any. I'll open a PR |
Yea even for me the updates are not atomic |
Could you elaborate on this? The test passes. Can you provide an example? |
Yea i tried as well the test you added is passing. |
@RahulLanjewar93 Why could it be working in parse-server tests but not in our own code? Did you run the test on your own infrastructure? The increment operation should be sent directly to mongo so therefore it should always be atomic independent of how many instances you are using? I am only using one instance |
Yea, increment ops in mongo are atomic. |
Although I haven't looked, I doubt that there is anything instance specific in the request that is sent to the DB. Maybe it's a DB issue? Or maybe it's an infrastructure issue where requests are lost, time out, or similar? Or maybe it is a more complex Parse JS SDK issue where multiple increments / decrements, and object re-fetches in between cause issues with caching? You could add a more complex test to the #8789 where you randomly increment / decrement / re-fetch an object in a loop and check whether the end result is still correct. |
New Issue Checklist
Issue Description
obj.increment does not appear to be atomic.
Steps to reproduce
I have the following code in the beforeSave hook of "childClass" and child has a pointer "parent" to "parentClass".
Actual Outcome
Creating two child objects simultaneously results in "number_children" increasing from 0 to 1.
This does not happen with:
but only with
Expected Outcome
I expected the count to increase from 0 to 2.
Environment
Server
6.2.2
MacOS Ventura
local
Database
MongoDB
6.0.10
MongoDB Atlas
Client
js
4.2.0
Logs
The text was updated successfully, but these errors were encountered: