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

ConfigBase with file read & write synchronization #8074

Merged

Conversation

kiminuo
Copy link
Collaborator

@kiminuo kiminuo commented May 19, 2022

Related to #7828

Makes sure that reading & writing of config files are mutually exclusive operations. This is a workaround for #7828 (comment).

Config classes are likely still plagued with concurrency issues. That might improve #7851 in the future (i.e. hopefully after the WW2 release).

@kiminuo kiminuo requested review from soosr and yahiheb May 19, 2022 19:51
@kiminuo kiminuo marked this pull request as ready for review May 19, 2022 19:51
@yahiheb
Copy link
Collaborator

yahiheb commented May 19, 2022

LGTM

@kiminuo kiminuo requested a review from molnard May 23, 2022 07:29
soosr
soosr previously approved these changes Jun 2, 2022
Copy link
Collaborator

@soosr soosr left a comment

Choose a reason for hiding this comment

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

First, the MethodNameLocked naming was odd to me as I thought the lock is inside of them, but it is the other way around, they have to be inside of the Lock.

Otherwise, LGTM.

@stale
Copy link

stale bot commented Aug 10, 2022

This has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 10, 2022
@stale stale bot closed this Sep 8, 2022
@yahiheb
Copy link
Collaborator

yahiheb commented Sep 8, 2022

@kiminuo What's up with this one?

@kiminuo kiminuo reopened this Sep 9, 2022
@kiminuo
Copy link
Collaborator Author

kiminuo commented Sep 9, 2022

@kiminuo What's up with this one?

There were some changes that make it non-trivial to fix the conflict. But the idea is still imho valid so I'll get to it. Hopefully soon.

@stale stale bot removed the stale label Sep 9, 2022
@stale
Copy link

stale bot commented Nov 9, 2022

This has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 9, 2022
@molnard molnard marked this pull request as draft November 10, 2022 09:50
@stale stale bot removed the stale label Nov 10, 2022
@molnard
Copy link
Collaborator

molnard commented Nov 10, 2022

Converted to draft until this is not a priority.

…2022-05-19-Config-synchronization

# Conflicts:
#	WalletWasabi/Bases/ConfigBase.cs
@stale
Copy link

stale bot commented Jan 16, 2023

This has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 16, 2023
@stale stale bot removed the stale label Jan 17, 2023
Copy link
Collaborator

@molnard molnard left a comment

Choose a reason for hiding this comment

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

LGTM. Can you check if TryEnsureBackwardsCompatibility is still required?

WalletWasabi/Bases/ConfigBase.cs Outdated Show resolved Hide resolved
@kiminuo kiminuo marked this pull request as ready for review January 17, 2023 14:29
@kiminuo
Copy link
Collaborator Author

kiminuo commented Jan 17, 2023

LGTM. Can you check if TryEnsureBackwardsCompatibility is still required?

The code was added in #1945 and it was 3 years ago. And as far as I understand that mechanism, it looks to me that to apply the BC changes, you just run WW and it immediately saves correct key-value pairs to your .json file.

So a person would have to not use her wallet for 3 years to observe an issue. The odds are very low for that to happen. Not sure if that old WW version still works at all.

I created #9958 for that.

Copy link
Collaborator

@molnard molnard left a comment

Choose a reason for hiding this comment

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

LGTM

@molnard molnard requested a review from Szpoti January 17, 2023 15:55
@molnard
Copy link
Collaborator

molnard commented Jan 18, 2023

BTW What was the original issue and how is this solving it? How was there a threading issue exactly?

@kiminuo
Copy link
Collaborator Author

kiminuo commented Jan 18, 2023

BTW What was the original issue

The original issue is #7828 and it simply shows that we can concurrently read & write config file which leads to exceptions.

and how is this solving it?

This PR adds locking around file reading and file writing operations.

How was there a threading issue exactly?

You can be in the process of writing the config file and then somebody attempts to read the config file (CheckFileChange).

Anyway, the sentence - Config classes are likely still plagued with concurrency issues. - from the OP still holds. This PR makes the situation better, not completely fixed though.

@molnard
Copy link
Collaborator

molnard commented Jan 20, 2023

You can be in the process of writing the config file and then somebody attempts to read the config file (CheckFileChange).

Can you elaborate a bit more? I don't understand how - it is surrounded by a lock:
https://github.com/molnard/WalletWasabi/blob/master/WalletWasabi/Bases/ConfigBase.cs#L50

@kiminuo
Copy link
Collaborator Author

kiminuo commented Jan 20, 2023

You can be in the process of writing the config file and then somebody attempts to read the config file (CheckFileChange).

Can you elaborate a bit more? I don't understand how - it is surrounded by a lock: https://github.com/molnard/WalletWasabi/blob/master/WalletWasabi/Bases/ConfigBase.cs#L50

I don't have it fresh in memory. You are right about the file contents, I think. It's been too long since I created the PR. But I guess I wanted to make sure that config data do not get corrupted.

One scenario that seems dangerous is when two threads can execute the following two lines:

Basically, we can populate config with data and at the same time we can try to deserialize it.

The approach of this PR is basically to be defensive and allow less parallel executions. That way you have a bigger chance that nothing gets corrupted or that your write is missed or you read older data (some previous config setting).

@molnard
Copy link
Collaborator

molnard commented Jan 23, 2023

Basically, we can populate config with data and at the same time we can try to deserialize it.

And why that generates The process cannot access the file exception?

The approach of this PR is basically to be defensive and allow less parallel executions.

I understand but it would be good to know how exactly the original issue happened. Anyway if we are not able to figure it out precisely, I am OK with this PR. From my side I have no idea how that happened, the original code should not do that either.

@kiminuo
Copy link
Collaborator Author

kiminuo commented Jan 23, 2023

And why that generates The process cannot access the file exception?

I think that exception message was fixed by introducing locks (a previous PR). If not, somebody will report a new issue hopefully. This PR builds on top of that to make it a little bit more better (defensive).

Copy link
Collaborator

@molnard molnard left a comment

Choose a reason for hiding this comment

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

ACK

@molnard molnard merged commit 707e23e into zkSNACKs:master Jan 24, 2023
@kiminuo kiminuo deleted the feature/2022-05-19-Config-synchronization branch January 24, 2023 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants