Python Ioctx should retain a reference to the cluster object
The following Python script segfaults:
import rados def make_ioctx(): cluster = rados.Rados(conffile='/etc/ceph/ceph.conf') cluster.connect() return cluster.open_ioctx("default") make_ioctx().stat("foobar")
This is because the cluster object is destroyed when the "cluster" local variable goes out of scope, even though the ioctx still needs it.
Python programmers will expect that the cluster object will not be destroyed until the last reference to it is removed. We expect that if the just-created ioctx requires a reference to the cluster object in order to function then it will retain one.
The failure is because the reference to the cluster object exists only at the C/C++ level, where Python cannot track it.Suggested fix:
- change Rados.ioctx() to pass a reference to itself to the Ioctx constructor
- have Ioctx.__init__() stash a reference to the cluster object using
self.cluster = cluster
- have Ioctx.close() remove the reference using
self.cluster = None