From dfcc0c1519d29efa8917d197acf522dcb37cc430 Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Wed, 29 Apr 2026 04:19:52 +0800 Subject: [PATCH] Give IB Gateway recovery more startup headroom --- scripts/recover_ib_gateway_ready.sh | 6 +++--- scripts/wait_for_ib_gateway_ready.sh | 2 +- tests/test_gateway_recovery_scripts.sh | 4 +++- tests/test_wait_for_ib_gateway_ready.sh | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/recover_ib_gateway_ready.sh b/scripts/recover_ib_gateway_ready.sh index 300d2fd..a664a9d 100755 --- a/scripts/recover_ib_gateway_ready.sh +++ b/scripts/recover_ib_gateway_ready.sh @@ -5,9 +5,9 @@ script_dir="$(cd "$(dirname "$0")" && pwd)" repo_dir="$(cd "${script_dir}/.." && pwd)" container_name="${IB_GATEWAY_CONTAINER_NAME:-ib-gateway}" gateway_mode="${1:-${IB_GATEWAY_MODE:-paper}}" -initial_wait_seconds="${IB_GATEWAY_RECOVERY_INITIAL_WAIT_SECONDS:-60}" -restart_wait_seconds="${IB_GATEWAY_RECOVERY_RESTART_WAIT_SECONDS:-180}" -recreate_wait_seconds="${IB_GATEWAY_RECOVERY_RECREATE_WAIT_SECONDS:-240}" +initial_wait_seconds="${IB_GATEWAY_RECOVERY_INITIAL_WAIT_SECONDS:-240}" +restart_wait_seconds="${IB_GATEWAY_RECOVERY_RESTART_WAIT_SECONDS:-300}" +recreate_wait_seconds="${IB_GATEWAY_RECOVERY_RECREATE_WAIT_SECONDS:-360}" cd "${repo_dir}" diff --git a/scripts/wait_for_ib_gateway_ready.sh b/scripts/wait_for_ib_gateway_ready.sh index 91567fa..49840f4 100644 --- a/scripts/wait_for_ib_gateway_ready.sh +++ b/scripts/wait_for_ib_gateway_ready.sh @@ -6,7 +6,7 @@ gateway_mode="${1:-${IB_GATEWAY_MODE:-paper}}" ready_timeout_seconds="${IB_GATEWAY_READY_TIMEOUT_SECONDS:-240}" poll_interval_seconds="${IB_GATEWAY_READY_POLL_INTERVAL_SECONDS:-5}" handshake_timeout_seconds="${IB_GATEWAY_HANDSHAKE_TIMEOUT_SECONDS:-12}" -healthcheck_client_id="${IB_GATEWAY_HEALTHCHECK_CLIENT_ID:-999}" +healthcheck_client_id="${IB_GATEWAY_HEALTHCHECK_CLIENT_ID:-$((9000 + (BASHPID % 9000)))}" case "${gateway_mode}" in paper) diff --git a/tests/test_gateway_recovery_scripts.sh b/tests/test_gateway_recovery_scripts.sh index ab5d9d8..ca66b94 100644 --- a/tests/test_gateway_recovery_scripts.sh +++ b/tests/test_gateway_recovery_scripts.sh @@ -16,7 +16,9 @@ test -x "$swap_script" test -x "$daily_restart_script" test -x "$health_watcher_script" -grep -Fq 'IB_GATEWAY_RECOVERY_INITIAL_WAIT_SECONDS:-60' "$recover_script" +grep -Fq 'IB_GATEWAY_RECOVERY_INITIAL_WAIT_SECONDS:-240' "$recover_script" +grep -Fq 'IB_GATEWAY_RECOVERY_RESTART_WAIT_SECONDS:-300' "$recover_script" +grep -Fq 'IB_GATEWAY_RECOVERY_RECREATE_WAIT_SECONDS:-360' "$recover_script" grep -Fq 'docker compose restart "${container_name}"' "$recover_script" grep -Fq 'docker compose up -d --force-recreate --no-build "${container_name}"' "$recover_script" grep -Fq 'IB_GATEWAY_READY_TIMEOUT_SECONDS="${timeout_seconds}"' "$recover_script" diff --git a/tests/test_wait_for_ib_gateway_ready.sh b/tests/test_wait_for_ib_gateway_ready.sh index e5d015f..6f8f86c 100644 --- a/tests/test_wait_for_ib_gateway_ready.sh +++ b/tests/test_wait_for_ib_gateway_ready.sh @@ -11,7 +11,7 @@ grep -Fq 'ready_timeout_seconds="${IB_GATEWAY_READY_TIMEOUT_SECONDS:-240}"' "$sc grep -Fq 'gateway_port=4002' "$script_file" grep -Fq 'gateway_port=4001' "$script_file" grep -Fq "docker inspect --format '{{.State.Running}}'" "$script_file" -grep -Fq 'IB_GATEWAY_HEALTHCHECK_CLIENT_ID:-999' "$script_file" +grep -Fq 'IB_GATEWAY_HEALTHCHECK_CLIENT_ID:-$((9000 + (BASHPID % 9000)))' "$script_file" grep -Fq 'check_api_handshake()' "$script_file" grep -Fq 'from ib_insync import IB' "$script_file" grep -Fq 'ib.connect(host, port, clientId=client_id, timeout=timeout_seconds)' "$script_file"