Skip to content

Commit cc6df48

Browse files
committed
Add null checks to io_callback and timer_callback in libev wrapper
This extends the segmentation fault fix to cover all libev callbacks that access Python objects during shutdown. Changes: 1. Add null checks in io_callback() before accessing self->callback 2. Add null checks in timer_callback() before accessing self->callback These prevent race conditions similar to the prepare_callback issue where libev callbacks could execute after Python objects are destroyed during driver shutdown.
1 parent bf4fb02 commit cc6df48

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

cassandra/io/libevwrapper.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ IO_dealloc(libevwrapper_IO *self) {
118118
static void io_callback(struct ev_loop *loop, ev_io *watcher, int revents) {
119119
libevwrapper_IO *self = watcher->data;
120120
PyObject *result;
121-
PyGILState_STATE gstate = PyGILState_Ensure();
121+
PyGILState_STATE gstate;
122+
123+
if (!self || !self->callback) {
124+
return; // Skip callback if object is being destroyed
125+
}
126+
127+
gstate = PyGILState_Ensure();
122128
if (revents & EV_ERROR && errno) {
123129
result = PyObject_CallFunction(self->callback, "Obi", self, revents, errno);
124130
} else {
@@ -477,6 +483,10 @@ static void timer_callback(struct ev_loop *loop, ev_timer *watcher, int revents)
477483
PyObject *result = NULL;
478484
PyGILState_STATE gstate;
479485

486+
if (!self || !self->callback) {
487+
return; // Skip callback if object is being destroyed
488+
}
489+
480490
gstate = PyGILState_Ensure();
481491
result = PyObject_CallFunction(self->callback, NULL);
482492
if (!result) {

0 commit comments

Comments
 (0)