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

Couch breaks with concurrent saves #113

Open
chbm opened this issue Aug 30, 2012 · 4 comments
Open

Couch breaks with concurrent saves #113

chbm opened this issue Aug 30, 2012 · 4 comments

Comments

@chbm
Copy link
Contributor

chbm commented Aug 30, 2012

Couchdb.prototype.put = function (id, doc, callback) {
  delete doc.id;
  return this.request('put', id, doc, function (e, res) {

put alters the original doc which means a save on the object will fail and create a duplicate cause we're saving a document without id. I'm not sure of the way to go here. Make a deep copy of the doc in put ?

@chbm
Copy link
Contributor Author

chbm commented Sep 1, 2012

Otoh I just realized this could be used as a crude semaphore. If !id return an error right away or better yet make the callback wait, return a error and the new document.

@Marak
Copy link
Contributor

Marak commented Sep 1, 2012

The couch engine should be using the _rev property for updating the same document multiple times.

If you can you provide a runnable code example or test reproducing the issue, I'd be glad to help you get it to work.

Thanks!

@chbm
Copy link
Contributor Author

chbm commented Sep 1, 2012

Well, the scenario is fairly simple but requires multiple code paths share the same object instance. If the following sequence runs:
obj.save(cb);

obj.save(othercb)

The 2nd save will find a obj without id but doesn't fail, instead it just creates a fresh duplicate under some new id.
One simple way is to say "you must always get() a fresh copy of the document before changing it" but I don't think this is a fair solution for a good deal of use cases.

@Marak
Copy link
Contributor

Marak commented Sep 1, 2012

If you can you provide a runnable code example or test reproducing the issue, I'd be glad to help you get it to work.

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

2 participants