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

Lock farm early in case it already exists to prevent potential damage of the JSON file #2668

Merged
merged 1 commit into from
Apr 15, 2024

Conversation

nazar-pc
Copy link
Member

@nazar-pc nazar-pc commented Apr 6, 2024

One farmer specified the same path twice with different sizes and that caused race condition during farm instantiation that corrupted JSON farm info. We can actually take a lock sooner and that way we wouldn't end up in this situation.

I decided to not invent anything fancy for the case of new farm creation since the risk and potential damage there is low.

Review with whitespace changes ignored, the diff is trivial.

Code contributor checklist:

);

single_disk_farm_info.store_to(directory)?;
single_disk_farm_info.store_to(directory)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that we write first and then secure a lock. Am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no file to lock yet in case we've just created new farm

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. We can create a lock on the directory first (possibly creating it as well) - I believe fs4 treats a directory as a file. However, I don't think it will matter in practice because we protect manual runs which don't expect to have race conditions.

@shamil-gadelshin shamil-gadelshin self-requested a review April 8, 2024 11:25
@nazar-pc nazar-pc added this pull request to the merge queue Apr 15, 2024
Merged via the queue into main with commit 189e83f Apr 15, 2024
22 checks passed
@nazar-pc nazar-pc deleted the prevent-accidential-farm-corruption branch April 15, 2024 17:31
@nazar-pc nazar-pc mentioned this pull request Apr 25, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants