Using 2 global connections to write to 2 different MongoDB instances
across threads misbehaves when using PyMongo 1.5.2 and modwsgi 2.5.
The *expected* behavior is that PyMongo's Connection class is
threadsafe due to the internal Pool class inheriting from
threading.local to keep a non-thread local list of sockets.

The *observed* behavior appears to be that the Pool.sockets list is
completely global -- meaning sockets are shared between the 2
connections.  The end result being queries are sent to a random
MongoDB instance regardless of which connection object is used.

I cross-posted this between the mongo and modwsgi mailing lists
because I'm unsure where the bug lies.

Using CherryPy's wsgiserver *or* modwsgi 3.2 works as expected, so
this may be a modwsgi 2.5 specific bug.

Steps to reproduce:

0.  Start 2 mongod instances (ports 27017 and 27018) with verbose logging (-vv)
1.  Copy this code into wsgitest.py: http://pastie.org/908053
2.  Add this code to an Apache vhost config: http://pastie.org/908065
3.  Restart Apache and run:
  sudo ab -c 20 -n 1000 http://localhost/wsgitest
4.  Watch as writes to the "c1" and "c2" databases show up in *both*
Mongo instances.

Switching to modwsgi 3.2 and following the above steps works as
expected (writes to the "c1" database only go to connection 1, etc).

Using CherryPy's wsgiserver also works:

  - Replace step 2 above with running the wsgitest.py file directly
(after installing CherryPy).
  - Change the URL in step 3 to http://localhost:8080/

If this is a known bug in modwsgi 2.5, I apologize for bringing it up
again.  Unfortunately a number of users could be hit by this bug as
modwsgi 2.5 is still distributed in many Linux distributions (using
Ubuntu 9.10 64bit here).

Thanks,
Michael Schurter (schmichael on #mongodb)

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to