Actions
Bug #10567
closedPython Ioctx should retain a reference to the cluster object
Status:
Resolved
Priority:
Urgent
Assignee:
-
Category:
librados
Target version:
-
% Done:
0%
Source:
other
Tags:
Backport:
Regression:
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:
Crash signature (v1):
Crash signature (v2):
Description
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
del self.cluster
orself.cluster = None
Actions