python-bson-ext does not encode binary in Apache with mod_wsgi
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MAAS |
Fix Released
|
Critical
|
Gavin Panella | ||
maas (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | ||
pymongo (Ubuntu) |
Invalid
|
Undecided
|
Unassigned |
Bug Description
In a component of MAAS we're using python-bson to dump out structures containing binary data. Everything works fine in development, but breaks in production under Apache.
In Python 2.x (we're using 2.7) it's necessary to wrap str/bytes objects in bson.binary.Binary; the encoder then does an isinstance check and encodes these objects as binary data - or "\x05" e_name binary, from the spec. However, under Apache our binary data is being encoded as string data - or "\x02" e_name string, from the spec. When decoding this becomes a unicode object, which chokes the next part of the MAAS's processing.
I think this is due to the C extension module. Apache and/or mod_wsgi does some weird things with Python contexts (I don't know much about this, just enough to know it can be a problem), and I suspect the PyObject_
The following are the mod_wsgi directives we're using in Apache:
{{{
WSGIDaemonProcess maas user=maas group=maas processes=2 threads=1 display-
# Without this, defining a tag as a malformed xpath expression will hang
# the region controller.
# See https:/
WSGIApplication
WSGIScriptAlias /MAAS /usr/share/
# Preload application when process starts. This will allow publishing
# the MAAS server existence over Avahi.
WSGIImportScript /usr/share/
WSGIPassAuthori
<Directory /usr/share/maas/>
WSGIProcess
</Directory>
}}}
$ apt-cache policy apache2 libapache2-mod-wsgi python-bson python-bson-ext
apache2:
Installed: 2.4.6-2ubuntu2
Candidate: 2.4.6-2ubuntu2
Version table:
*** 2.4.6-2ubuntu2 0
500 http://
100 /var/lib/
libapache2-
Installed: 3.4-4
Candidate: 3.4-4
Version table:
*** 3.4-4 0
500 http://
100 /var/lib/
python-bson:
Installed: 2.6-1
Candidate: 2.6-1
Version table:
*** 2.6-1 0
500 http://
100 /var/lib/
python-bson-ext:
Installed: 2.6-1
Candidate: 2.6-1
Version table:
*** 2.6-1 0
500 http://
100 /var/lib/
Changed in maas: | |
status: | New → Triaged |
importance: | Undecided → Critical |
Changed in maas: | |
assignee: | nobody → Gavin Panella (allenap) |
status: | Triaged → Fix Committed |
milestone: | none → 13.10 |
Changed in maas: | |
status: | Fix Committed → Fix Released |
Changed in maas (Ubuntu): | |
status: | New → Fix Released |
Changed in pymongo (Ubuntu): | |
status: | New → Invalid |
http:// emptysqua. re/blog/ python- c-extensions- and-mod- wsgi/ has some answers. I'm still not sure how to change our Apache config though as it has most of the hacks in place already.