Merge lp:~therve/storm/mutable-variables-flush-leak into lp:storm

Proposed by Thomas Herve
Status: Merged
Merged at revision: not available
Proposed branch: lp:~therve/storm/mutable-variables-flush-leak
Merge into: lp:storm
Diff against target: 60 lines
2 files modified
storm/variables.py (+6/-1)
tests/store/base.py (+26/-0)
To merge this branch: bzr merge lp:~therve/storm/mutable-variables-flush-leak
Reviewer Review Type Date Requested Status
Jürgen Kartnaller (community) Approve
Jamu Kakar (community) Approve
Review via email: mp+12827@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Thomas Herve (therve) wrote :

This another corner-case bug when you use ListVariable or PickleVariable, reported by Jürgen Kartnaller. The fix is fairly trivial (if it's the correct one), the test isn't so great though.

Revision history for this message
Jamu Kakar (jkakar) wrote :

I can't think of a better way to test this issue. +1!

review: Approve
Revision history for this message
Jürgen Kartnaller (jukart) wrote :

This patch is already in production in a web-service for 5 web sites.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storm/variables.py'
2--- storm/variables.py 2009-03-04 16:56:58 +0000
3+++ storm/variables.py 2009-10-03 18:25:19 +0000
4@@ -550,7 +550,7 @@
5 Variable.__init__(self, *args, **kwargs)
6 if self.event is not None:
7 self.event.hook("start-tracking-changes", self._start_tracking)
8- self.event.hook("object-deleted", self._detect_changes)
9+ self.event.hook("object-deleted", self._detect_changes_and_stop)
10
11 def _start_tracking(self, obj_info, event_system):
12 self._event_system = event_system
13@@ -564,6 +564,11 @@
14 if (self._checkpoint_state is not Undef and
15 self.get_state() != self._checkpoint_state):
16 self.event.emit("changed", self, None, self._value, False)
17+
18+ def _detect_changes_and_stop(self, obj_info):
19+ self._detect_changes(obj_info)
20+ if self._event_system is not None:
21+ self._stop_tracking(obj_info, self._event_system)
22
23 def get(self, default=None, to_db=False):
24 if self._event_system is not None:
25
26=== modified file 'tests/store/base.py'
27--- tests/store/base.py 2009-07-31 01:53:08 +0000
28+++ tests/store/base.py 2009-10-03 18:25:19 +0000
29@@ -421,6 +421,32 @@
30 self.store.flush()
31 self.assertEquals(len(events), 1)
32
33+ def test_wb_flush_event_with_deleted_object_before_flush(self):
34+ """
35+ When an object is deleted before flush and it contains mutable
36+ variables, those variables unhook from the global event system to
37+ prevent a leak.
38+ """
39+ class PickleBlob(Blob):
40+ bin = Pickle()
41+
42+ # Disable the cache, which holds strong references.
43+ self.get_cache(self.store).set_size(0)
44+
45+ blob = self.store.get(Blob, 20)
46+ blob.bin = "\x80\x02}q\x01U\x01aK\x01s."
47+ self.store.flush()
48+ del blob
49+ gc.collect()
50+
51+ pickle_blob = self.store.get(PickleBlob, 20)
52+ pickle_blob.bin = "foobin"
53+ del pickle_blob
54+
55+ self.store.flush()
56+ self.assertEquals(self.store._event._hooks["flush"], set())
57+
58+
59 def test_obj_info_with_deleted_object_with_get(self):
60 # Same thing, but using get rather than find.
61

Subscribers

People subscribed via source and target branches

to status/vote changes: