cloudant / python-cloudant

A Python library for Cloudant and CouchDB
Apache License 2.0
163 stars 55 forks source link

409 conflict happens with multiple connection instances #399

Closed zhaoxin closed 6 years ago

zhaoxin commented 6 years ago

Bug Description

1. Steps to reproduce and the simplest code sample possible to demonstrate the issue

I have several flask app as gevent workers of gunicorn like this: gunicorn -b 0.0.0.0:5000 --worker-class gevent -w 8 main:app

In the top of the app, I connect to my CouchDB server like this: cdb = CouchDB( "userxxx", "pwdxxx", url="http://xxx:5984", auto_renew=True, connect=True, )

So I guess I have 8 CouchDB instances along with 8 gevent workers.

2. What you expected to happen

When I post new data of a document id with rev=3 to one of the api in the flask app, the code fetch the document from cdb with id first, then set the new data and save it. The fetched doc should have the same rev=3, and after save the new rev=4.

3. What actually happened

The fetched doc has a smaller rev like 2 or 1, so the save returns 409 error. After make gunicorn worker count to 1, no error occurs.

So does this related to multiple instances of client.CouchDB?

Environment details

rajinib commented 6 years ago

@zhaoxin this most likely is a side effect of eventual consistency. If one flask app updates the document then immediately after another flask app calls fetch there may not have been enough time for the modifications to your doc to replicate within CouchDB. There's a good explanation of this in a CouchDB case study.

rajinib commented 6 years ago

Closing as stale, please reopen if you require further assistance.