tvalentyn opened a new issue, #33966: URL: https://github.com/apache/beam/issues/33966
### What happened? Beam SDK has a mechanism to provide status report to a runner that captures the ongoing work. The status report includes [stacktraces of running threads](https://github.com/apache/beam/blob/332a61d848181672d328694f3dca52755e7611eb/sdks/python/apache_beam/runners/worker/worker_status.py#L221). To collect such stacktraces, we inspect the content of running Python frames via [`sys._current_frames()`](https://github.com/apache/beam/blob/332a61d848181672d328694f3dca52755e7611eb/sdks/python/apache_beam/runners/worker/worker_status.py#L60). It appears that on Python 3.11, such invocation can cause a deadlock a garbage collection triggers during the call to `sys._current_frames()`: https://github.com/python/cpython/issues/106883. The issues is not reproducible on Python 3.10 or Python 3.12. On Python 3.11, a Beam job might get stuck. An example manifestation of a stuck job running on Dataflow might look like the following. Inspecting Dataflow logs reveals errors like: _Unable to retrieve status info from SDK harness sdk_harness_id within allowed time_ _SDK worker appears to be permanently unresponsive. Aborting the SDK._ As noted in https://cloud.google.com/dataflow/docs/guides/common-errors#worker-lost-contact , such errors can happen when a thread in Python process permanently holds the GIL. Inspecting the Dataflow workers with pystack, for example via an automated script like: https://gist.github.com/tvalentyn/82fcee6b93253740d2ae50bd425916a5 , reveals a thread with a stacktrace in `frames = sys._current_frames()` holding the GIL and a thread doing garbage collecting; sometimes these are also the same thread: ``` Traceback for thread 107 (python) [Has the GIL,Garbage collecting] (most recent call last): (C) File "Python/thread_pthread.h", line 241, in pythread_wrapper (/usr/local/lib/libpython3.11.so.1.0) (C) File "./Modules/_threadmodule.c", line 1124, in thread_run (/usr/local/lib/libpython3.11.so.1.0) (Python) File "/usr/local/lib/python3.11/threading.py", line 1002, in _bootstrap self._bootstrap_inner() (Python) File "/usr/local/lib/python3.11/threading.py", line 1045, in _bootstrap_inner self.run() (Python) File "/usr/local/lib/python3.11/threading.py", line 982, in run self._target(*self._args, **self._kwargs) (Python) File "/usr/local/lib/python3.11/site-packages/apache_beam/runners/worker/worker_status.py", line 175, in <lambda> target=lambda: self._serve(), name='fn_api_status_handler') (Python) File "/usr/local/lib/python3.11/site-packages/apache_beam/runners/worker/worker_status.py", line 200, in _serve id=request.id, status_info=self.generate_status_response())) (Python) File "/usr/local/lib/python3.11/site-packages/apache_beam/runners/worker/worker_status.py", line 219, in generate_status_response all_status_sections.append(thread_dump()) (Python) File "/usr/local/lib/python3.11/site-packages/apache_beam/runners/worker/worker_status.py", line 60, in thread_dump frames = sys._current_frames() # pylint: disable=protected-access (C) File "Modules/gcmodule.c", line 2290, in gc_alloc (inlined) (/usr/local/lib/libpython3.11.so.1.0) (C) File "Modules/gcmodule.c", line 1400, in gc_collect_with_callback (/usr/local/lib/libpython3.11.so.1.0) (C) File "Modules/gcmodule.c", line 1287, in gc_collect_main (/usr/local/lib/libpython3.11.so.1.0) (C) File "Modules/gcmodule.c", line 1013, in delete_garbage (inlined) (/usr/local/lib/libpython3.11.so.1.0) (C) File "Objects/typeobject.c", line 1279, in subtype_clear (/usr/local/lib/libpython3.11.so.1.0) (C) File "Objects/typeobject.c", line 1463, in subtype_dealloc (/usr/local/lib/libpython3.11.so.1.0) (C) File "./Modules/_threadmodule.c", line 904, in local_dealloc (/usr/local/lib/libpython3.11.so.1.0) (C) File "./Modules/_threadmodule.c", line 872, in local_clear (/usr/local/lib/libpython3.11.so.1.0) (C) File "Python/thread_pthread.h", line 497, in PyThread_acquire_lock_timed (/usr/local/lib/libpython3.11.so.1.0) ``` ### Issue Priority Priority: 2 (default / most bugs should be filed as P2) ### Issue Components - [x] Component: Python SDK - [ ] Component: Java SDK - [ ] Component: Go SDK - [ ] Component: Typescript SDK - [ ] Component: IO connector - [ ] Component: Beam YAML - [ ] Component: Beam examples - [ ] Component: Beam playground - [ ] Component: Beam katas - [ ] Component: Website - [ ] Component: Infrastructure - [ ] Component: Spark Runner - [ ] Component: Flink Runner - [ ] Component: Samza Runner - [ ] Component: Twister2 Runner - [ ] Component: Hazelcast Jet Runner - [ ] Component: Google Cloud Dataflow Runner -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
