-
Notifications
You must be signed in to change notification settings - Fork 242
fix: remove incorrect noexcept from resource handle functions #1489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: remove incorrect noexcept from resource handle functions #1489
Conversation
|
/ok to test 4e70324 |
This comment has been minimized.
This comment has been minimized.
rwgk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I did not scrutinize the case-by-case keep/remove decisions for the noexcepts. I assume an LLM was used to figure out those details.
|
Should we add some cpp linting now that we have a significant amount of code to maintain there? Not in this PR of course :) |
Functions that allocate memory (via new, std::make_shared, or container operations) can throw std::bad_alloc. Marking them noexcept causes std::terminate on OOM instead of allowing graceful error handling. Changes: - Remove noexcept from 22 C++ functions that can throw - Keep noexcept on 5 functions that truly cannot throw: get_last_error, peek_last_error, clear_last_error, deallocation_stream, set_deallocation_stream - Update Cython .pxd/.pyx to use "nogil except+" for throwing functions - Wrap clear_mempool_peer_access in try-catch (std::vector can throw) - Wrap IPC cache deleter operations in try-catch (std::lock_guard can throw) This allows C++ exceptions to be translated to Python exceptions by Cython, enabling proper error handling instead of process termination. Based on feedback from Leo Fang, Lawrence Mitchell, and Vyas Ramasubramani.
4e70324 to
2e1a8dc
Compare
yes! |
|
/ok to test 2e1a8dc |
|
Summary
noexceptfrom C++ resource handle functions that can thrownogil except+for proper exception translationChanges
1. Remove incorrect
noexceptfrom throwing functionsFunctions that allocate memory (via
new,std::make_shared, or container operations) can throwstd::bad_alloc. Marking themnoexceptcausesstd::terminateon OOM instead of allowing graceful error handling.Remove
noexceptfrom 22 functions:create_*functions (context, stream, event, mempool, deviceptr)deviceptr_alloc*functionsget_primary_context,get_current_context,get_device_mempoolget_legacy_stream,get_per_thread_streamKeep
noexcepton 5 functions that truly cannot throw:get_last_error,peek_last_error,clear_last_errordeallocation_stream,set_deallocation_stream2. Update Cython declarations
Change from
noexcept nogiltonogil except+for all throwing functions, allowing Cython to translate C++ exceptions to Python exceptions.3. Fix exception-unsafe deleters
Custom
shared_ptrdeleters must not throw (undefined behavior per C++ standard). Two deleters had potential issues:clear_mempool_peer_access: Usesstd::vectorwhich can throwstd::bad_alloc. Wrapped in try-catch.std::lock_guardwhich can throwstd::system_error. Wrapped cache operations in try-catch.