From b41ba6e4f09856b60a3e18f5442591c22501be0b Mon Sep 17 00:00:00 2001 From: kzangeli Date: Sat, 19 Sep 2026 09:36:12 +0200 Subject: [PATCH] fix: wait for the IoT-Agent to be ready, and retry the device batches waitForIoTAgent loops while the HTTP code is 000, so it stops waiting as soon as the port answers ANYTHING - including the 503 the agent serves while still initialising. link-devices then runs against an agent that is not ready. IoT-Agent, IoT-Agent-JSON and Big-Data-Spark already wait on the container health status; this brings it into line. link-devices also POSTs several ~30 KB device batches with no retry, under 'set -e'. The agent intermittently closes the connection without replying (curl exit 52, 'empty reply from server'), most often on the batch immediately following provision-devices - and one such reply kills the script silently, leaving the tutorial stopped at 'Link Devices to Animal entities' with no error shown. Verified intermittent: the identical payload against the same agent gave exit=52 then exit=0 back to back, and a single device is accepted with 201 throughout, so it is not a size limit (31 KB against a 1 MB expressLimit). With --retry on those two calls the tutorial starts cleanly. --- link-devices | 4 ++-- services | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/link-devices b/link-devices index 2de7b84..11562ac 100755 --- a/link-devices +++ b/link-devices @@ -42,7 +42,7 @@ do fi done -curl -s -o /dev/null -X POST \ +curl -s -o /dev/null --retry 10 --retry-all-errors --retry-delay 10 -X POST \ 'http://iot-agent:4041/iot/devices' \ -H 'Content-Type: application/json' \ -H 'fiware-service: openiot' \ @@ -74,7 +74,7 @@ do fi done -curl -s -o /dev/null -X POST \ +curl -s -o /dev/null --retry 10 --retry-all-errors --retry-delay 10 -X POST \ 'http://iot-agent:4041/iot/devices' \ -H 'Content-Type: application/json' \ -H 'fiware-service: openiot' \ diff --git a/services b/services index caa4554..a3e596f 100755 --- a/services +++ b/services @@ -126,9 +126,9 @@ waitForMongo () { waitForIoTAgent () { echo -e "\n⏳ Waiting for \033[1;36mIoT-Agent\033[0m to be available\n" - while [ "$(docker run --network fiware_default --rm quay.io/curl/curl:${CURL_VERSION} -s -o /dev/null -w %{http_code} 'http://iot-agent:4041/version')" -eq 000 ] + while ! [ "$(docker inspect --format='{{.State.Health.Status}}' fiware-iot-agent 2>/dev/null)" == "healthy" ] do - echo -e "IoT Agent HTTP state: " $(curl -s -o /dev/null -w %{http_code} 'http://localhost:4041/version') " (waiting for 200)" + echo -e "IoT Agent health: $(docker inspect --format='{{.State.Health.Status}}' fiware-iot-agent 2>/dev/null) (waiting for healthy)" sleep 6 done }