Skip to content

Commit 261dffe

Browse files
committed
fix: retry pending report_status instead of forcing re-download
When report_status fails due to a transient server error (e.g., HTTP 502 during server maintenance), the agent previously deleted its local checksums, forcing a full re-download and re-apply on the next cycle. This is wasteful since the configuration was already applied successfully. Instead, save the pending status to a marker file and retry report_status on the next polling cycle without re-downloading. This ensures the controller receives the status update as soon as the server recovers, without unnecessary network traffic or config re-application. Backward compatible: older controllers will simply receive the delayed report_status and update their status accordingly.
1 parent d3b6ae1 commit 261dffe

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

openwisp-config/files/openwisp.agent

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ REGISTRATION_PARAMETERS="$WORKING_DIR/registration_parameters"
200200
TEST_CHECKSUM="$WORKING_DIR/test_checksum"
201201
UPDATE_INFO="$WORKING_DIR/update_info"
202202
STATUS_REPORT="$WORKING_DIR/status_report"
203+
PENDING_REPORT="$WORKING_DIR/pending_report"
203204
APPLYING_CONF="$WORKING_DIR/applying_conf"
204205
UPDATE_CONFIG_LOG="$WORKING_DIR/update-config.log"
205206
BOOTUP="$WORKING_DIR/bootup"
@@ -825,6 +826,7 @@ update_configuration() {
825826
result=$?
826827
fi
827828

829+
local status_to_report
828830
if [ "$result" -eq "0" ]; then
829831
logger "Configuration applied successfully" \
830832
-t openwisp \
@@ -833,14 +835,22 @@ update_configuration() {
833835
env -i ACTION="config-applied" /sbin/hotplug-call openwisp
834836
# store the new checksum as last known checksum
835837
cp "$CONFIGURATION_CHECKSUM" "$PERSISTENT_CHECKSUM"
838+
status_to_report="applied"
836839
retry_with_backoff report_status "applied"
837840
else
841+
status_to_report="error"
838842
retry_with_backoff report_status "error"
839843
fi
840-
# if reporting of the status fails, let it retry in the next cycle
844+
# if reporting of the status fails, save the pending status for retry
845+
# in the next cycle without forcing a full re-download
841846
# shellcheck disable=SC2181
842847
if [ "$?" -ne "0" ]; then
843-
rm -f $CONFIGURATION_CHECKSUM $PERSISTENT_CHECKSUM
848+
echo "$status_to_report" >"$PENDING_REPORT"
849+
logger -s "report_status failed, will retry in the next cycle" \
850+
-t openwisp \
851+
-p daemon.warning
852+
else
853+
rm -f "$PENDING_REPORT"
844854
fi
845855

846856
rm $APPLYING_CONF
@@ -987,6 +997,19 @@ while true; do
987997

988998
if [ "$?" -eq "1" ]; then
989999
update_configuration
1000+
elif [ -f "$PENDING_REPORT" ]; then
1001+
# Retry a previously failed report_status without re-downloading.
1002+
# This handles the case where the config was applied successfully
1003+
# but report_status failed due to a transient server error.
1004+
local pending_status
1005+
pending_status=$(cat "$PENDING_REPORT")
1006+
logger "Retrying pending report_status: $pending_status" \
1007+
-t openwisp \
1008+
-p daemon.info
1009+
retry_with_backoff report_status "$pending_status"
1010+
if [ "$?" -eq "0" ]; then
1011+
rm -f "$PENDING_REPORT"
1012+
fi
9901013
fi
9911014
env -i ACTION="end-of-cycle" /sbin/hotplug-call openwisp
9921015

0 commit comments

Comments
 (0)