2022 05 11 tor race condition (#4333)

* WIP tor race condition debug

* Fix race condition between starting node and starting tor

* Remove extra log
This commit is contained in:
Chris Stewart 2022-05-11 16:38:24 -05:00 committed by GitHub
parent 6845caf778
commit 5036b37729
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 6 deletions

View file

@ -29,9 +29,9 @@ trait NativeProcessFactory extends Logging {
/** Starts the binary by spinning up a new process */
def startBinary(): Future[Unit] = Future {
processOpt match {
case Some(_) =>
case Some(p) =>
//don't do anything as it is already started
logger.debug(s"Binary was already started!")
logger.info(s"Binary was already started! process=$p")
()
case None =>
if (cmd.nonEmpty) {

View file

@ -169,7 +169,14 @@ class BitcoinSServerMain(override val serverArgParser: ServerArgParser)(implicit
val callbacksF =
chainApiF.map(chainApi => buildNeutrinoCallbacks(wsQueue, chainApi))
val startedNodeF = configuredNodeF.flatMap(_.start())
val startedNodeF = {
//can't start connecting to peers until tor is done starting
for {
_ <- startedTorConfigF
started <- configuredNodeF.flatMap(_.start())
} yield started
}
val startedWalletF = configuredWalletF.flatMap(_.start())
val startedDLCNodeF = dlcNodeF
.flatMap(_.start())

View file

@ -127,7 +127,11 @@ object TorClient extends Logging {
//set files as executable
torBundle.executables.foreach { f =>
val executable = datadir.resolve(f)
executable.toFile.setExecutable(true)
val isExecutable = executable.toFile.setExecutable(true)
if (!isExecutable) {
sys.error(
s"Could not make file=${executable.toAbsolutePath} executable")
}
}
// write geoip files
@ -139,7 +143,6 @@ object TorClient extends Logging {
logger.info(
s"Using prepackaged Tor from bitcoin-s resources, $executableFileName")
executableFileName
}
}

View file

@ -105,7 +105,7 @@ case class TorAppConfig(
* place for our node.
*/
override def start(): Future[Unit] = {
if (torProvided) {
val f = if (torProvided) {
logger.info(s"Tor provided to us, skipping start")
Future.unit
} else {
@ -121,6 +121,7 @@ case class TorAppConfig(
torLogFile.toFile.delete()
}
val client = createClient
for {
_ <- client.startBinary()
_ = Runtime.getRuntime.addShutdownHook(new Thread() {
@ -147,6 +148,8 @@ case class TorAppConfig(
Future.unit
}
}
f.failed.foreach(err => logger.error("Error starting TorAppConfig", err))
f
}
override def stop(): Future[Unit] = {