Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unlock farm explicitly on drop #2356

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions crates/subspace-farmer/src/single_disk_farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,17 @@ impl SingleDiskFarmId {
/// Exclusive lock for single disk farm info file, ensuring no concurrent edits by cooperating processes is done
#[must_use = "Lock file must be kept around or as long as farm is used"]
pub struct SingleDiskFarmInfoLock {
_file: File,
file: File,
}

impl Drop for SingleDiskFarmInfoLock {
fn drop(&mut self) {
use fs4::FileExt;

if let Err(error) = self.file.unlock() {
error!(%error, "Failed to unlock single disk farm lock");
}
}
}

/// Important information about the contents of the `SingleDiskFarm`
Expand Down Expand Up @@ -174,7 +184,7 @@ impl SingleDiskFarmInfo {
let file = File::open(directory.join(Self::FILE_NAME))?;
fs4::FileExt::try_lock_exclusive(&file)?;

Ok(SingleDiskFarmInfoLock { _file: file })
Ok(SingleDiskFarmInfoLock { file })
}

// ID of the farm
Expand Down
Loading