Skip to content

Commit c19d52a

Browse files
committed
be more responsive when waiting for xud to be ready
1 parent 6682d93 commit c19d52a

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

images/utils/launcher/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,5 @@ def launch(self):
255255
print()
256256
except NoWaiting:
257257
pass
258+
except FatalError as e:
259+
print("💀 %s." % str(e))

images/utils/launcher/node/xud.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from launcher.table import ServiceTable
1414
from launcher.utils import yes_or_no, normalize_path
15-
from launcher.errors import NoWaiting
15+
from launcher.errors import NoWaiting, FatalError
1616
from .base import Node, CliBackend, CliError
1717
from .lnd import CFHeaderState
1818

@@ -484,6 +484,25 @@ def _wait_tls_cert(self, stop: threading.Event):
484484
break
485485
stop.wait(1)
486486

487+
def _wait_xud_ready(self, stop: threading.Event):
488+
# Error: ENOENT: no such file or directory, open '/root/.xud/tls.cert'
489+
# xud is starting... try again in a few seconds
490+
# xud is locked, run 'xucli unlock', 'xucli create', or 'xucli restore' then try again
491+
cmd = self._cli + " getinfo -j"
492+
while not stop.is_set():
493+
try:
494+
if not self.is_running:
495+
raise FatalError("XUD container \"%s\" stopped unexpectedly" % self.container_name)
496+
exit_code, output = self.exec(cmd)
497+
if exit_code == 0:
498+
break
499+
if "xud is locked" in output:
500+
break
501+
logger.debug("[Execute] %s (exit_code=%s)\n%s", cmd, exit_code, output.rstrip())
502+
except docker.errors.APIError:
503+
logger.exception("Failed to getinfo")
504+
stop.wait(1)
505+
487506
def ensure_ready(self, stop: threading.Event):
488507
logger.info("Ensuring XUD is ready")
489508

@@ -496,33 +515,30 @@ def ensure_ready(self, stop: threading.Event):
496515

497516
logger.info("Waiting for XUD to be ready")
498517
executor = self.config.executor
499-
f = executor.submit(self._wait_tls_cert, stop)
500518

519+
f = executor.submit(self._wait_tls_cert, stop)
501520
while not stop.is_set():
502521
logger.info("Waiting for XUD tls.cert to be created")
503522
try:
504523
f.result(30)
524+
break
505525
except TimeoutError:
506-
print("XUD should not take so much time to create \"tls.cert\" file. please check container \"%s\" logs for more details." % self.container_name)
526+
print("XUD should not take so long to create \"tls.cert\" file. please check container \"%s\" logs for more details." % self.container_name)
507527
reply = yes_or_no("Would you like to keep waiting?")
508528
if reply == "no":
509529
raise NoWaiting
510530

511-
# Error: ENOENT: no such file or directory, open '/root/.xud/tls.cert'
512-
# xud is starting... try again in a few seconds
513-
# xud is locked, run 'xucli unlock', 'xucli create', or 'xucli restore' then try again
514-
cmd = self._cli + " getinfo -j"
531+
f = executor.submit(self._wait_xud_ready, stop)
515532
while not stop.is_set():
533+
logger.info("Waiting for XUD to be ready")
516534
try:
517-
exit_code, output = self.exec(cmd)
518-
if exit_code == 0:
519-
break
520-
if "xud is locked" in output:
521-
break
522-
logger.debug("[Execute] %s (exit_code=%s)\n%s", cmd, exit_code, output.rstrip())
523-
except docker.errors.APIError:
524-
logger.exception("Failed to getinfo")
525-
stop.wait(1)
535+
f.result(10)
536+
break
537+
except TimeoutError:
538+
print("XUD should not take so long to be ready. please check container \"%s\" logs for more details." % self.container_name)
539+
reply = yes_or_no("Would you like to keep waiting?")
540+
if reply == "no":
541+
raise NoWaiting
526542

527543
if not self.has_wallets():
528544
logger.info("Setting up XUD wallets")

0 commit comments

Comments
 (0)