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

fix(core): fix geth --init temp dir race condition #2068

Merged
merged 2 commits into from Jan 22, 2023

Conversation

Rjected
Copy link
Contributor

@Rjected Rjected commented Jan 21, 2023

Motivation

Previously, if multiple instances of geth were spawned concurrently, only one directory would be used to populate geth's genesis.json. This can lead to a race condition where the genesis.json would be re-written by a second instance, before the first instance reads the genesis.json for populating its db and genesis block with the geth --init command. this was possible because directory returned by std::env::temp_dir() is often shared.

Solution

This fixes the race condition by using tempfile::tempdir(), which creates a unique directory per call to tempdir().

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog
  • Breaking changes

 * previously, if multiple instances of geth were spawned concurrently,
   only one directory would be used to populate geth's genesis.json.
   this can lead to a race condition where the genesis.json would be
   re-written by a second instance, before the first instance reads the
   genesis.json for populating its db and genesis block with the geth
   --init command. this was possible because directory returned by
   std::env::temp_dir() is often shared
 * fixes the race condition by using tempfile::tempdir(), which creates
   a unique directory per call to tempdir()
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

for some reason this caused the wasm job to fail,
unused dependency, otherwise lgtm, nice catch

@Rjected
Copy link
Contributor Author

Rjected commented Jan 21, 2023

just added:

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tempfile = { version = "3.3.0", default-features = false }

to fix the unused dependency

@gakonst gakonst merged commit e9a808e into gakonst:master Jan 22, 2023
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.

None yet

3 participants