From ae2d9bfe383f6d75089fe4ab6bb8f22cd80a1ac3 Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Thu, 28 May 2026 13:11:10 +0800 Subject: [PATCH] Fix IB gateway readiness healthcheck --- scripts/recover_ib_gateway_ready.sh | 2 +- scripts/wait_for_ib_gateway_ready.sh | 8 +++++++- tests/test_gateway_recovery_scripts.sh | 2 +- tests/test_wait_for_ib_gateway_ready.sh | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/recover_ib_gateway_ready.sh b/scripts/recover_ib_gateway_ready.sh index 997bec4..9e02885 100755 --- a/scripts/recover_ib_gateway_ready.sh +++ b/scripts/recover_ib_gateway_ready.sh @@ -8,7 +8,7 @@ compose_service_name="${IB_GATEWAY_COMPOSE_SERVICE_NAME:-ib-gateway}" gateway_mode="${1:-${IB_GATEWAY_MODE:-paper}}" 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}" +recreate_wait_seconds="${IB_GATEWAY_RECOVERY_RECREATE_WAIT_SECONDS:-600}" lock_file="${IB_GATEWAY_RECOVERY_LOCK_FILE:-/var/lock/ib_gateway_recovery.lock}" lock_wait_seconds="${IB_GATEWAY_RECOVERY_LOCK_WAIT_SECONDS:-900}" diff --git a/scripts/wait_for_ib_gateway_ready.sh b/scripts/wait_for_ib_gateway_ready.sh index cc363f1..20ff1be 100644 --- a/scripts/wait_for_ib_gateway_ready.sh +++ b/scripts/wait_for_ib_gateway_ready.sh @@ -53,7 +53,13 @@ if IB is not None: ib = IB() try: try: - ib.connect(host, port, clientId=client_id, timeout=timeout_seconds) + ib.connect( + host, + port, + clientId=client_id, + timeout=timeout_seconds, + readonly=True, + ) accounts = ib.managedAccounts() if not accounts: raise RuntimeError("IB API healthcheck did not receive managed accounts") diff --git a/tests/test_gateway_recovery_scripts.sh b/tests/test_gateway_recovery_scripts.sh index 0a40f37..f3ce1f1 100644 --- a/tests/test_gateway_recovery_scripts.sh +++ b/tests/test_gateway_recovery_scripts.sh @@ -21,7 +21,7 @@ test -x "$unit_helper_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 'IB_GATEWAY_RECOVERY_RECREATE_WAIT_SECONDS:-600' "$recover_script" grep -Fq 'IB_GATEWAY_RECOVERY_LOCK_FILE:-/var/lock/ib_gateway_recovery.lock' "$recover_script" grep -Fq 'IB_GATEWAY_RECOVERY_LOCK_WAIT_SECONDS:-900' "$recover_script" grep -Fq 'flock -n 9' "$recover_script" diff --git a/tests/test_wait_for_ib_gateway_ready.sh b/tests/test_wait_for_ib_gateway_ready.sh index 6f8f86c..f26a387 100644 --- a/tests/test_wait_for_ib_gateway_ready.sh +++ b/tests/test_wait_for_ib_gateway_ready.sh @@ -14,7 +14,7 @@ grep -Fq "docker inspect --format '{{.State.Running}}'" "$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" +grep -Fq 'readonly=True' "$script_file" grep -Fq 'IB API ib_insync healthcheck ready' "$script_file" grep -Fq 'b"API\0" + struct.pack(">I", len(b"v157..176")) + b"v157..176"' "$script_file" grep -Fq 'has_next_valid_id and has_managed_accounts' "$script_file"