From 444328ea3f53a612be53ba4964a2a7b5f9d4aafb Mon Sep 17 00:00:00 2001 From: Hongchao Deng Date: Tue, 9 Jul 2024 13:39:41 -0700 Subject: [PATCH] [core] catch exception in async_callback (#46488) (#46519) backport. fix `python/ray/tests/test_asyncio.py::test_on_completed_callback_refcount[True]` Signed-off-by: hongchaodeng --- python/ray/_raylet.pyx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/ray/_raylet.pyx b/python/ray/_raylet.pyx index 7783d9cc38a5..ccddfbe4f4ed 100644 --- a/python/ray/_raylet.pyx +++ b/python/ray/_raylet.pyx @@ -5154,6 +5154,10 @@ cdef void async_callback(shared_ptr[CRayObject] obj, user_callback = user_callback_ptr user_callback(result) + except Exception: + # Only log the error here because this calllback is called from Cpp + # and Cython will ignore the exception anyway + logger.exception(f"failed to run async callback (user func)") finally: # NOTE: we manually increment the Python reference count of the callback when # registering it in the core worker, so we must decrement here to avoid a leak.