From f302908b824d036e2a4930df0c0174d31927b191 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 4 Feb 2026 15:43:15 -0800 Subject: [PATCH] client: plugins: tor: implement retries when bootstrapping --- client/plugins/docker/tor.bash | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/client/plugins/docker/tor.bash b/client/plugins/docker/tor.bash index f81139e..a0138fc 100755 --- a/client/plugins/docker/tor.bash +++ b/client/plugins/docker/tor.bash @@ -102,12 +102,25 @@ function tor::start() local -r _sleep="30s" lib_utils::print_info "${global_container}: testing connection (bootstrapping ~${_sleep})" sleep "$_sleep" # Give time to bootstrap - # TODO: run timer to verify response (and fail if N times if no response) - docker exec "$global_container" \ - /bin/bash -i -c " - proxychains curl -s https://check.torproject.org 2>/dev/null \ - | grep -B3 'Your IP address appears to be' \ - | sed -e 's/^ //g' -e '\$ s/[^\\.0-9]//g' -e '/^\$/d' -e '2,3d'" || lib_utils::die_fatal + + local _tries=1 + while [ $_tries -ne 3 ]; do + lib_docker::exec "proxychains curl -s https://check.torproject.org 2>/dev/null \ + | grep -B3 'Your IP address appears to be' \ + | sed -e 's/^ //g' -e '\$ s/[^\\.0-9]//g' -e '/^\$/d' -e '2,3d' \ + | grep -A2 --color=never Congratulations || exit 1 2>/dev/null" 2>/dev/null + if [ $? -ne 0 ]; then + lib_utils::print_warning "Could not bootstrap, trying again (${_tries}/3)" + docker exec "$tor_container" /bin/sh -c "pkill -HUP tor" || lib_utils::die_fatal + sleep "$_sleep" + ((_tries++)) + else + break + fi + done + if [ $_tries -eq 3 ]; then + lib_utils::die_fatal "Could not successfully bootstrap! \`restart\` this instance" + fi } function tor::stop()