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

downloader: manual .lock remove may lead to race and creation of data files without .torrent #9782

Merged
merged 16 commits into from
Apr 11, 2024

Conversation

AskAlexSharov
Copy link
Collaborator

@AskAlexSharov AskAlexSharov commented Mar 22, 2024

if !prohibited(file) && !exists(file) {
   create(file)
}

such pattern is always race - even if prohibited/exists()/create() are atomic inside.
to eliminate race - need move towards analog of CompareAndSwap - CreateIfNotProhibited which in 1 mutex lock will: check_lock, existence, create.

@AskAlexSharov AskAlexSharov changed the title downloader: manual .lock remove may lead to race and creation of data files without .torrent [wip] downloader: manual .lock remove may lead to race and creation of data files without .torrent Mar 22, 2024
if !tf.exists(name) && !prohibited {
err = tf.create(name, res)
if err != nil {
return nil, false, false, err
Copy link
Member

Choose a reason for hiding this comment

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

created is always false.

Does it makes sense to just check lock file exists on the start instead of checking it per file? Like, we started, downloads either prohibited or not, that's it. Could be changed only with restart.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

“ instead of checking it per file? ” - this feature is just introduced by Giulio - to prevent downloading 1 type of file (he working on nee type of file): #9766
Don’t know: maybe it was doable by creating special branch in “erigon-snapshots” repo (maybe not).

Copy link

sonarcloud bot commented Mar 26, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@AskAlexSharov AskAlexSharov changed the title [wip] downloader: manual .lock remove may lead to race and creation of data files without .torrent downloader: manual .lock remove may lead to race and creation of data files without .torrent Mar 26, 2024
}
func (tf *TorrentFiles) create(torrentFilePath string, res []byte) error {

func (tf *TorrentFiles) CreateIfNotProhibited(name string, res []byte) (ts *torrent.TorrentSpec, prohibited, created bool, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

prohibited and created results are not used anywhere - are they going to be used in a future PR? if not then should we remove them from the func signature?

also looks like created is always returned as false - seems like we are missing a statement to set created to true and return that in the case of a file getting created

@awskii awskii merged commit c756a55 into devel Apr 11, 2024
7 checks passed
@awskii awskii deleted the d_race branch April 11, 2024 15:34
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.

3 participants