Skip to content

Commit b5828e4

Browse files
mergify[bot]jd
andauthored
fix(profiling): copy greenlet list before iterating (#3484) (#3511)
There is a short window of time where the list can be modified by the coroutine tracer which triggers this kind of errors: Unhandled exception in thread started by <bound method _GeventPeriodicThread.run of <_GeventPeriodicThread(ddtrace.profiling.collector.stack:StackCollector, initial daemon)>> Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/ddtrace/internal/periodic.py", line 141, in run self._target() File "/usr/local/lib/python2.7/site-packages/ddtrace/profiling/collector/__init__.py", line 42, in periodic for events in self.collect(): File "ddtrace/profiling/collector/stack.pyx", line 480, in ddtrace.profiling.collector.stack.StackCollector.collect File "ddtrace/profiling/collector/stack.pyx", line 298, in ddtrace.profiling.collector.stack.stack_collect File "ddtrace/profiling/collector/_task.pyx", line 96, in ddtrace.profiling.collector._task.list_tasks File "ddtrace/profiling/collector/_task.pyx", line 114, in ddtrace.profiling.collector._task.list_tasks File "/usr/local/lib/python2.7/weakref.py", line 157, in iteritems for wr in self.data.itervalues(): RuntimeError: dictionary changed size during iteration This might be quite specific to Python 2.7, but this should help fixing this. (cherry picked from commit 2caa92d) Co-authored-by: Julien Danjou <[email protected]>
1 parent 1327bee commit b5828e4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ddtrace/profiling/collector/_task.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ cpdef list_tasks(thread_id):
111111
(greenlet_id,
112112
_threading.get_thread_name(greenlet_id),
113113
greenlet.gr_frame)
114-
for greenlet_id, greenlet in compat.iteritems(_gevent_tracer.greenlets)
114+
for greenlet_id, greenlet in list(compat.iteritems(_gevent_tracer.greenlets))
115115
if not greenlet.dead
116116
])
117117

0 commit comments

Comments
 (0)