Race condition when adding nodes via API

Steps to reproduce

Write a script that would run to identical API requests to add a new node to any existing node. The key here is to not wait until the first request finishes before starting the new one.

Use the /doc/edit API with changes containing only one insert item.

Open the node to which you will be adding items in Dynalist before running the script.

Expected result

Both inserted nodes should show up. They should be still there after I refresh the page or re-run the app.

Actual result

The inserted nodes do show up — both of them. BUT, after I refresh the page, one of them is gone.

I suppose they show up initially due to the Websocket updates. However, due to a race condition on the server, only one of them gets to be stored in the database.

Environment

I use the latest Mojave and Safari 12.0.3 for the web client, but otherwise, the environment doesn’t matter.

I’m gonna move this to the Developers category.

@Shida: could you take a look at this?

That’s strange… Internally in the server, a lock is taken whenever a document is about to be modified which is only released by a database commit. That should make sure any concurrent modifications are run in serial…

If what you’re describing is true then I will need to perform some tests to debug the problem.

1 Like