mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
util: use ClusterConnection.Copy() for re-using connections
Connections are reference counted, so just assigning the connection to an other object for re-use is not correct. This can cause connections to be garbage collected while something else is still using it. Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
6e941539b5
commit
5c26fbb0d7
@ -68,6 +68,22 @@ func (cc *ClusterConnection) Destroy() {
|
||||
}
|
||||
}
|
||||
|
||||
// Copy creates a copy of the ClusterConnection. This is needed when an other
|
||||
// object needs to use the existing connection.
|
||||
// It is required to call Destroy() once the (copied) connection is not used
|
||||
// anymore.
|
||||
func (cc *ClusterConnection) Copy() *ClusterConnection {
|
||||
if cc.conn == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
c := ClusterConnection{}
|
||||
c.discardOnZeroedWriteSameDisabled = cc.discardOnZeroedWriteSameDisabled
|
||||
c.conn = connPool.Copy(cc.conn)
|
||||
|
||||
return &c
|
||||
}
|
||||
|
||||
func (cc *ClusterConnection) GetIoctx(pool string) (*rados.IOContext, error) {
|
||||
if cc.conn == nil {
|
||||
return nil, errors.New("cluster is not connected yet")
|
||||
|
Reference in New Issue
Block a user