Open kevinjqiu opened 7 years ago
Have you thought about the possibility that there is a CouchDB bug, rather than a bug in CouchDB-Python? In particular, I think observation 4 (thanks for the detailed report!) suggests that the bug might not be in CouchDB-Python.
My other thought is that this might have to do with the connection pooling we're doing in couchdb.http
.
One question I have is, when you run this test case for 100 times (or 10), does it fail every time? My expectation would be for it to be intermittent.
Hi @djc
Have you thought about the possibility that there is a CouchDB bug
On couchdb's end, the requests were carried out successfully. I can see in the couchdb logs there are three concurrent GET requests, all responded with 200 OK
. Also, I can use the requests library to call the endpoints concurrently without issue. Those observations lead me to think it's some sort of race condition inside CouchDB-Python.
One question I have is, when you run this test case for 100 times (or 10), does it fail every time
Yes, it fails every single time.
I might be able to reduce the sample code even further to only use couchdb.http
methods to reproduce the issue. Out of curiosity, why CouchDB-Python didn't use the stock EDIT: I see you built httplib
? Sorry I'm not too familiar with the genesis of this project.ConnectionPool
on top of httplib
.
@djc A tentative fix for the race condition: https://github.com/djc/couchdb-python/pull/314
There appears to be a race condition and the bug exists in both Python 2.x and Python 3.x, although they're manifested differently.
Minimum code to reproduce the bug:
Observation 1: When run on Python 2.x, the following error is encountered:
Observation 2: When run on Python 3.x, the execution hangs, and when you 'Ctrl+C' to terminate the program, the following stack trace is printed:
Observation 3 If I change the pool size to 1 (essentially serialize the GET operations), the bug does not exist. Same happens when I try to debug it with visual studio code (whose debugger practically blocks the execution of other processes), the code runs without issue.
Observation 4 If I run a proxy server in front of couchdb (e.g., haproxy), the code runs without issue.