Recovery: RecoveriesCollection.findRecoveryByShard should call recoveryStatus.tryIncRef before accessing fields
The function iterates over a snapshot of on going recoveries and thus may access RecoveryStatus objects that are already finished. Closes #8231
This commit is contained in:
parent
bb7ad4ab96
commit
7f14674ff5
|
@ -130,11 +130,16 @@ public class RecoveriesCollection {
|
|||
@Nullable
|
||||
public StatusRef findRecoveryByShard(IndexShard indexShard) {
|
||||
for (RecoveryStatus recoveryStatus : onGoingRecoveries.values()) {
|
||||
if (recoveryStatus.indexShard() == indexShard) {
|
||||
// check if the recovery has already finished and if not protect
|
||||
// against it being closed on us while we check
|
||||
if (recoveryStatus.tryIncRef()) {
|
||||
try {
|
||||
if (recoveryStatus.indexShard() == indexShard) {
|
||||
recoveryStatus.incRef();
|
||||
return new StatusRef(recoveryStatus);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} finally {
|
||||
recoveryStatus.decRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue