lanto03 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

2 PUT requests are sent for a single db.save() request #200

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. See http://pastebin.ca/2083227 for the save subroutine
2. Get 409 errors in couchdb logs occasionally. 

What is the expected output? What do you see instead?

Do not return 409 error, and the document should be saved successfully. 

What version of the product are you using? On what operating system?

Python Couchdb - 0.8 on Debian Linux Lenny

Please provide any additional information below.

I have checked the couchdb logs and I get two PUT request with the same id 

[Tue, 27 Sep 2011 07:15:51 GMT] [info] [<0.20476.5>] 127.0.0.1 - - 'PUT' 
/archive_201109/202af5e1466b43f1890b609d95d9e800 201
[Tue, 27 Sep 2011 07:15:51 GMT] [info] [<0.20511.5>] 127.0.0.1 - - 'PUT' 
/archive_201109/202af5e1466b43f1890b609d95d9e800 409
[Tue, 27 Sep 2011 07:15:58 GMT] [info] [<0.20511.5>] 127.0.0.1 - - 'GET' 
/archive_201109/202af5e1466b43f1890b609d95d9e800 200

The first request succeeds, for some reason python-couchdb makes a second 
request which fails, and returns that result to the program. It should not have 
made the second request.

Original issue reported on code.google.com by rajkum...@gmail.com on 27 Sep 2011 at 9:01

GoogleCodeExporter commented 8 years ago
This is not normal - couchdb-python 0.8 and the main development both behave as 
expected on my machine (Ubuntu 11.04).

Can you provide working example code we can run that reliably reporoduces the 
problem? Also, is there anything else in your environment, e.g. an HTTP proxy, 
that could be affecting things?

Original comment by matt.goo...@gmail.com on 27 Sep 2011 at 9:19

GoogleCodeExporter commented 8 years ago
Just have tried adopted version of your script against CouchDB 1.1.0 on Gentoo 
Linux 3.0.4:

import logging
import couchdb
from uuid import uuid4
from couchdb.http import ResourceConflict

db = couchdb.Database('http://localhost:5984/temp')

def insert_couchdb( msg):
    doc_id = uuid4().hex
    try:
        msg['_id'] = doc_id
        db.save(msg)
    except ResourceConflict:
        logging.warn('Possible doc save failure id: %s db: %s' % (doc_id, db.name))
        #time.sleep(6)
        if not db[doc_id]:
            logging.warn('Failed save a doc with id %s db: %s' % (doc_id, db.name))
            logging.debug('%s %s' % (doc_id, msg))
            return False
    except:
        logging.error('Unknown exception while trying to save document id: %s db: %s' % (doc_id, db.name))
        return False
    return True
insert_couchdb({'foo':'bar'})

...and it doesn't reproduced for me and never was. Could you provide additional 
info about CouchDB version and is there any proxies in front of it? This 
behavior is quite common for POST requests so I wonder why it happened for PUT 
one.

Original comment by kxepal on 27 Sep 2011 at 9:24

GoogleCodeExporter commented 8 years ago
Hi all,

Thanks for your comments. 

I am using 1.1.0 now, but the same error happened in 0.11 also. There are no 
proxies in between my program and couchdb.

This issue does not happen consistently. See this for example:

tail -n 10000 /var/log/couchdb.log | grep PUT | awk '{print $14}' | sort | uniq 
-c 
   8168 201
    609 409

tail -n 100000 /var/log/couchdb.log | grep PUT | awk '{print $14}' | sort | 
uniq -c 
  49398 201
   4383 409

Let me know if any more information is required.

with regards,

raj

Original comment by rajkum...@gmail.com on 28 Sep 2011 at 5:42

GoogleCodeExporter commented 8 years ago
Since we haven't been able to reproduce this, closing.

Original comment by djc.ochtman on 6 Jul 2014 at 12:15