From 8ccbe9e39ec0de8d0b6027cf171a86e612c7cb06 Mon Sep 17 00:00:00 2001 From: Devin Bileck <603793+devinbileck@users.noreply.github.com> Date: Mon, 11 Mar 2019 13:03:58 -0700 Subject: [PATCH] Fix exception handling during Tor setup A recent change in the netlayer is now seeing exceptions wrapped in a TorCtlException if an error occurs while setting up Tor. So when an issue such as "Auth cookie not created" (#2398) occurs, which was previously raised as an IOException, it was restarting Tor rather than showing the error message to the user. --- .../bisq/network/p2p/network/TorNetworkNode.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/p2p/src/main/java/bisq/network/p2p/network/TorNetworkNode.java b/p2p/src/main/java/bisq/network/p2p/network/TorNetworkNode.java index aad0eb3a585..6659c603640 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/TorNetworkNode.java +++ b/p2p/src/main/java/bisq/network/p2p/network/TorNetworkNode.java @@ -282,10 +282,18 @@ public void run() { }); log.info("It will take some time for the HS to be reachable (~40 seconds). You will be notified about this"); } catch (TorCtlException e) { - log.error("Tor node creation failed: " + (e.getCause() != null ? e.getCause().toString() : e.toString())); - restartTor(e.getMessage()); + String msg = e.getCause() != null ? e.getCause().toString() : e.toString(); + log.error("Tor node creation failed: {}", msg); + if (e.getCause() instanceof IOException) { + // Since we cannot connect to Tor, we cannot do nothing. + // Furthermore, we have no hidden services started yet, so there is no graceful + // shutdown needed either + UserThread.execute(() -> setupListeners.forEach(s -> s.onSetupFailed(new RuntimeException(msg)))); + } else { + restartTor(e.getMessage()); + } } catch (IOException e) { - log.error("Could not connect to running Tor: " + e.getMessage()); + log.error("Could not connect to running Tor: {}", e.getMessage()); // Since we cannot connect to Tor, we cannot do nothing. // Furthermore, we have no hidden services started yet, so there is no graceful // shutdown needed either