mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
fix: possible connection leaks in sets init, heal (#9263)
This commit is contained in:
parent
c6e62b9175
commit
4714958e99
@ -221,10 +221,16 @@ func IsServerResolvable(endpoint Endpoint) error {
|
||||
// connect to list of endpoints and load all XL disk formats, validate the formats are correct
|
||||
// and are in quorum, if no formats are found attempt to initialize all of them for the first
|
||||
// time. additionally make sure to close all the disks used in this attempt.
|
||||
func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints, zoneCount, setCount, drivesPerSet int, deploymentID string) ([]StorageAPI, *formatXLV3, error) {
|
||||
func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints, zoneCount, setCount, drivesPerSet int, deploymentID string) (storageDisks []StorageAPI, format *formatXLV3, err error) {
|
||||
// Initialize all storage disks
|
||||
storageDisks, errs := initStorageDisksWithErrors(endpoints)
|
||||
|
||||
defer func(storageDisks []StorageAPI) {
|
||||
if err != nil {
|
||||
closeStorageDisks(storageDisks)
|
||||
}
|
||||
}(storageDisks)
|
||||
|
||||
for i, err := range errs {
|
||||
if err != nil {
|
||||
if err != errDiskNotFound {
|
||||
@ -256,7 +262,7 @@ func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints,
|
||||
// most part unless one of the formats is not consistent
|
||||
// with expected XL format. For example if a user is
|
||||
// trying to pool FS backend into an XL set.
|
||||
if err := checkFormatXLValues(formatConfigs, drivesPerSet); err != nil {
|
||||
if err = checkFormatXLValues(formatConfigs, drivesPerSet); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@ -266,7 +272,7 @@ func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints,
|
||||
zoneCount, setCount, drivesPerSet)
|
||||
|
||||
// Initialize erasure code format on disks
|
||||
format, err := initFormatXL(context.Background(), storageDisks, setCount, drivesPerSet, deploymentID)
|
||||
format, err = initFormatXL(context.Background(), storageDisks, setCount, drivesPerSet, deploymentID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -293,7 +299,7 @@ func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints,
|
||||
// This migration failed to capture '.This' field properly which indicates
|
||||
// the disk UUID association. Below function is called to handle and fix
|
||||
// this regression, for more info refer https://github.com/minio/minio/issues/5667
|
||||
if err := fixFormatXLV3(storageDisks, endpoints, formatConfigs); err != nil {
|
||||
if err = fixFormatXLV3(storageDisks, endpoints, formatConfigs); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@ -302,7 +308,7 @@ func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints,
|
||||
return nil, nil, errXLV3ThisEmpty
|
||||
}
|
||||
|
||||
format, err := getFormatXLInQuorum(formatConfigs)
|
||||
format, err = getFormatXLInQuorum(formatConfigs)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -238,6 +238,9 @@ func (s *xlSets) connectDisks() {
|
||||
}
|
||||
disk.SetDiskID(format.XL.This)
|
||||
s.xlDisksMu.Lock()
|
||||
if s.xlDisks[setIndex][diskIndex] != nil {
|
||||
s.xlDisks[setIndex][diskIndex].Close()
|
||||
}
|
||||
s.xlDisks[setIndex][diskIndex] = disk
|
||||
s.xlDisksMu.Unlock()
|
||||
go func(setIndex int) {
|
||||
@ -333,16 +336,21 @@ func newXLSets(endpoints Endpoints, storageDisks []StorageAPI, format *formatXLV
|
||||
endpoints = append(endpoints, s.endpoints[i*drivesPerSet+j])
|
||||
// Rely on endpoints list to initialize, init lockers and available disks.
|
||||
s.xlLockers[i][j] = newLockAPI(s.endpoints[i*drivesPerSet+j])
|
||||
if storageDisks[i*drivesPerSet+j] == nil {
|
||||
disk := storageDisks[i*drivesPerSet+j]
|
||||
if disk == nil {
|
||||
continue
|
||||
}
|
||||
diskID, derr := disk.GetDiskID()
|
||||
if derr != nil {
|
||||
disk.Close()
|
||||
continue
|
||||
}
|
||||
if diskID, derr := storageDisks[i*drivesPerSet+j].GetDiskID(); derr == nil {
|
||||
m, n, err := findDiskIndexByDiskID(format, diskID)
|
||||
if err != nil {
|
||||
disk.Close()
|
||||
continue
|
||||
}
|
||||
s.xlDisks[m][n] = storageDisks[i*drivesPerSet+j]
|
||||
}
|
||||
s.xlDisks[m][n] = disk
|
||||
}
|
||||
|
||||
// Initialize xl objects for a given set.
|
||||
@ -1375,11 +1383,13 @@ func (s *xlSets) ReloadFormat(ctx context.Context, dryRun bool) (err error) {
|
||||
|
||||
diskID, err := disk.GetDiskID()
|
||||
if err != nil {
|
||||
disk.Close()
|
||||
continue
|
||||
}
|
||||
|
||||
m, n, err := findDiskIndexByDiskID(refFormat, diskID)
|
||||
if err != nil {
|
||||
disk.Close()
|
||||
continue
|
||||
}
|
||||
|
||||
@ -1583,11 +1593,13 @@ func (s *xlSets) HealFormat(ctx context.Context, dryRun bool) (res madmin.HealRe
|
||||
|
||||
diskID, err := disk.GetDiskID()
|
||||
if err != nil {
|
||||
disk.Close()
|
||||
continue
|
||||
}
|
||||
|
||||
m, n, err := findDiskIndexByDiskID(refFormat, diskID)
|
||||
if err != nil {
|
||||
disk.Close()
|
||||
continue
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user