Project

General

Profile

Actions

Bug #13115

closed

librbd python bindings eat exceptions in callbacks

Added by Hector Martin over 8 years ago. Updated over 8 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
Target version:
-
% Done:

0%

Source:
Community (dev)
Tags:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:
Crash signature (v1):
Crash signature (v2):

Description

If an exception happens in a Python callback (e.g. the argument to rbd_image.diff_iterate), ctypes prints it out to stderr and eats it, then returns garbage instead.

I've investigated if there is a way around this, but haven't found one; even if the Python side attempts to wrap the called code in a try/except and do something sane with exceptions, there is always a window outside the try block where exceptions may arrive (e.g. an asynchronous KeyboardInterrupt caused by SIGINT) that would result in silently missed callbacks with no indication to the caller. In practice, this means diff_iterate cannot be relied upon since a successful result might hide an exception thrown by a callback.

Here's a simple testcase of the problem with ctypes and exceptions:

from ctypes import *

def cb():
    raise KeyboardInterrupt()

CB = CFUNCTYPE(c_int)
cb_c = CB(cb)
res = cb_c()
print "result=", res

Callback exceptions should be converted to a negative (error) return back into diff_iterate, and then when diff_iterate returns an error back to its caller, it should propagate the underlying Python exception to the calling Python code. It doesn't seem this is possible with ctypes at the moment.

I am investigating working around this by building my own librbd Python bindings using Cython (which we already do for librados for other reasons), which should make this implementation possible (and, incidentally, Cython is also faster than ctypes). Would the Ceph project be interested in having this upstreamed as a replacement for the ctypes bindings (particularly if it's API-compatible)?


Files

rbd.pyx (42.6 KB) rbd.pyx Rough version of Cython bindings for librbd Hector Martin, 09/18/2015 08:12 AM
Actions

Also available in: Atom PDF