[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Limit number of events buffered by interpreter
commit 66243c4110d9116e6dfabdb0d8694fe1f04e6227
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Oct 29 23:56:48 2017 -0700
Limit number of events buffered by interpreter
Sweet jesus that was a pita to track down. Nyx has a memory leak, holding onto
events tor emits indefinitely. Spent all day headscratching and finally found
it. Our control interpreter intercepts events and enqueues them without bound.
Finally caught thanks to the gc module...
to_ignore = [ locals(), globals(), gc.garbage ]
log.warn("refs: %s" % [inspect.getframeinfo(r) for r in gc.get_referrers(event_message) if r not in to_ignore])
... which gave...
06:44:50 [NYX_WARNING] refs: [Traceback(filename='/home/ubuntu/nyx/stem/interpreter/commands.py', lineno=135, function='handle_event_wrapper',
code_context=[' handle_event_real(event_message)\n'], index=0), Traceback(filename='/home/ubuntu/nyx/stem/control.py', lineno=3812,
function='_handle_event', code_context=[' log.warn("refs: %s" % [inspect.getframeinfo(r) for r in gc.get_referrers(event_message) if r not in
to_ignore])\n'], index=0), Traceback(filename='/home/ubuntu/nyx/stem/control.py', lineno=975, function='_event_loop', code_context=['
self._handle_event(event_message)\n'], index=0)] [998 duplicates hidden]
---
stem/interpreter/commands.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/stem/interpreter/commands.py b/stem/interpreter/commands.py
index 45f2e2ca..d47cccdd 100644
--- a/stem/interpreter/commands.py
+++ b/stem/interpreter/commands.py
@@ -26,6 +26,8 @@ try:
except ImportError:
from io import StringIO
+MAX_EVENTS = 100
+
def _get_fingerprint(arg, controller):
"""
@@ -133,7 +135,10 @@ class ControlInterpreter(code.InteractiveConsole):
def handle_event_wrapper(event_message):
handle_event_real(event_message)
- self._received_events.append(event_message)
+ self._received_events.insert(0, event_message)
+
+ if len(self._received_events) > MAX_EVENTS:
+ self._received_events.pop()
self._controller._handle_event = handle_event_wrapper
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits