Skip to content

Commit d3e832d

Browse files
Guard close() in io callbacks against dead connections
When handle_io_in raises because the connection is already dead (thisptr == NULL), the error handler called close() which raised a second ReferenceError. This unhandled exception escaped the cdef callback, corrupting C-side buffer state and triggering g_string_erase assertion failures. Check thisptr before calling close() in both handle_io_in_cb and handle_io_out_cb error handlers.
1 parent 5c5988f commit d3e832d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

modules/python/binding.pyx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ cdef int handle_io_in_cb(c_connection *con, void *context, void *data, int size)
825825
l = instance.handle_io_in(bdata)
826826
except BaseException:
827827
logging.error("There was an error in the Python service", exc_info=True)
828-
instance.close()
828+
if instance.thisptr != NULL:
829+
instance.close()
829830
return len(bdata)
830831
return l
831832

@@ -837,7 +838,8 @@ cdef void handle_io_out_cb(c_connection *con, void *context) noexcept with gil:
837838
instance.handle_io_out()
838839
except BaseException:
839840
logging.error("There was an error in the Python service", exc_info=True)
840-
instance.close()
841+
if instance.thisptr != NULL:
842+
instance.close()
841843

842844
cdef c_bool handle_disconnect_cb(c_connection *con, void *context) except * with gil:
843845
# print "disconnect_cb"

0 commit comments

Comments
 (0)