Skip to content

Commit 31175f9

Browse files
authored
fix race condition in statesampler with lock for reset (#39129)
* fix race condition with lock for reset * add nogil
1 parent af005ef commit 31175f9

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

sdks/python/apache_beam/runners/worker/statesampler_fast.pyx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,14 @@ cdef class StateSampler(object):
153153
self.sampling_thread.join()
154154

155155
def reset(self):
156-
for state in self.scoped_states_by_index:
157-
(<ScopedState>state)._nsecs = 0
158-
self.started = self.finished = False
156+
with nogil:
157+
pythread.PyThread_acquire_lock(self.lock, pythread.WAIT_LOCK)
158+
try:
159+
for state in self.scoped_states_by_index:
160+
(<ScopedState>state)._nsecs = 0
161+
self.started = self.finished = False
162+
finally:
163+
pythread.PyThread_release_lock(self.lock)
159164

160165
cpdef ScopedState current_state(self):
161166
return self.current_state_c()

0 commit comments

Comments
 (0)