Iterating over a WeakKeyDictionary isn't thread-safe

Bug #574399 reported by Anthony Lenton
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
wsgi-oops
Fix Committed
Undecided
Anthony Lenton

Bug Description

Working with the latest wsgi-oops, we sometimes get the following
Traceback (most recent call last):
  File "/srv/login.staging.ubuntu.com/staging/framework/django.wsgi", line 46, in application
    return oops(environ, start_response)
  File "/usr/lib/python2.5/site-packages/canonical/oops/wsgi.py", line 70, in __call__
    response_trapper = ResponseTrapper(self.serial, environ, start_response)
  File "/usr/lib/python2.5/site-packages/canonical/oops/wsgi.py", line 88, in __init__
    environ['OOPSID'] = self.oops.assign_id()
  File "/usr/lib/python2.5/site-packages/canonical/oops/oops.py", line 66, in assign_id
    self.id = self._oops_id_factory()
  File "/usr/lib/python2.5/site-packages/canonical/oops/serializer.py", line 171, in get_next_oops_id
    day, sequence = self.get_next_sequence()
  File "/usr/lib/python2.5/site-packages/canonical/oops/serializer.py", line 159, in get_next_sequence
    serializer in self._serializers[self._key])
  File "/usr/lib/python2.5/site-packages/canonical/oops/serializer.py", line 158, in <genexpr>
    sequence = max(serializer.get_initial_sequence() for
  File "/usr/lib/python2.5/weakref.py", line 303, in iterkeys
    for wr in self.data.iterkeys():
RuntimeError: dictionary changed size during iteration

You usually see this error pop up a couple of times during load tests.

Related branches

Revision history for this message
Tim Cole (tcole) wrote :

Apparently iterators obtained from WeakKeyDictionaries aren't threadsafe, since finalization may modify the underlying dict at any time. For now, we can avoid using iterators obtained from WeakKeyDictionaries, but this is arguably a bug in WeakKeyDictionary.

Revision history for this message
Anthony Lenton (elachuni) wrote :

Confirmed, the tracebacks go away by avoiding iterators on WeakKeyDictionary.

Revision history for this message
Anthony Lenton (elachuni) wrote :

This is an upstream Python bug, http://bugs.python.org/issue839159

summary: - wsgi-oops still isn't thread-safe
+ Iterating over a WeakKeyDictionary isn't thread-safe
description: updated
Changed in wsgi-oops:
status: New → In Progress
assignee: nobody → Anthony Lenton (elachuni)
Changed in wsgi-oops:
status: In Progress → Fix Committed
Tom Haddon (mthaddon)
tags: added: canonical-losa-isd
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.