Project

General

Profile

Bug #10567

Python Ioctx should retain a reference to the cluster object

Added by Kim Vandry about 5 years ago. Updated almost 5 years ago.

Status:
Resolved
Priority:
Urgent
Assignee:
-
Category:
librados
Target version:
-
% Done:

0%

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

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 about 5 years ago

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

#2 Updated by Kefu Chai almost 5 years ago

  • Status changed from 12 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