Project

General

Profile

Bug #10567

Python Ioctx should retain a reference to the cluster object

Added by Kim Vandry over 4 years ago. Updated over 4 years ago.

Status:
Resolved
Priority:
Urgent
Assignee:
-
Category:
librados
Target version:
-
Start date:
01/18/2015
Due date:
% Done:

0%

Source:
other
Tags:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:

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 or self.cluster = None

Related issues

Related to Ceph - Bug #8797: "ceph status" do not exit with python_2.7.8 Resolved 07/09/2014

History

#1 Updated by Dan Mick over 4 years ago

  • Status changed from New to Verified
  • Priority changed from Normal to Urgent

#2 Updated by Kefu Chai over 4 years ago

  • Status changed from Verified to Resolved

as a side effect of the fix for #8797. we do not have Rados.__del__() anymore. so i consider it as resolved.

Also available in: Atom PDF