[fix] Retry registration on transient controller 5xx errors#262
[fix] Retry registration on transient controller 5xx errors#262MichaelUray wants to merge 1 commit into
Conversation
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe registration flow now inspects the controller response status line before validating controller headers. HTTP 5xx responses are logged as warnings and return status Estimated code review effort: 2 (Simple) | ~10 minutes Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (2 errors, 1 warning)
✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@openwisp-config/files/openwisp.agent`:
- Around line 356-361: Update the registration failure logging in the 5xx branch
to strip the trailing carriage return from the first line before passing it to
logger, and quote REGISTRATION_PARAMETERS in the command substitution to
preserve the intended file path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 19a6cba1-d5a9-4a17-b4c1-d10ad52283f7
📒 Files selected for processing (1)
openwisp-config/files/openwisp.agent
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
- GitHub Check: QA-Checks and Tests
- GitHub Check: Kilo Code Review
f3e54b3 to
87264ba
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@openwisp-config/files/openwisp.agent`:
- Line 356: Update the status check in the REGISTRATION_PARAMETERS handling to
match 5xx codes followed by whitespace or end-of-line, rather than requiring a
trailing reason phrase. Preserve the existing transient-error path so HTTP/2
responses such as “503” are handled before check_header().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: e80caed4-cbd7-47df-ac36-3945e26a70b0
📒 Files selected for processing (1)
openwisp-config/files/openwisp.agent
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
- GitHub Check: QA-Checks and Tests
- GitHub Check: Kilo Code Review
During registration the agent called check_header() before checking the HTTP status. A transient server-side error (HTTP 5xx, e.g. 502/503/504 from a reverse proxy while the backend is restarting) carries no X-Openwisp-Controller header, so check_header treated it as a wrong server and called `exit 4`. Combined with procd's respawn limit (respawn ... 5), a short controller outage during (re)registration made procd give up permanently, leaving the agent dead until a manual restart. The other three check_header call sites (get_checksum, update_info, status report) already guard with an `is_http_status ... 200` check before calling check_header, so a 5xx there returns a retryable code. Only the registration path was missing this guard. Treat a 5xx registration response as a temporary failure (return 2, retryable) before check_header runs. Non-5xx responses still go through check_header, preserving the "wrong server" safety (exit 4) for a 2xx response without the controller header. Signed-off-by: Michael Uray <michaeluray@users.noreply.github.com>
87264ba to
28b3e21
Compare
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
Reviewed by hy3:free · Input: 38.4K · Output: 1.7K · Cached: 142.6K |
|
@coderabbitai review Both earlier review comments are addressed in the latest commit (28b3e21): the HTTP status line now has its trailing carriage return stripped and the variable is quoted, and the 5xx match is anchored to the status line ( |
🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- Changed files and latest PR diff ---'
git diff --stat HEAD^ HEAD
git diff -- openwisp-config/files/openwisp.agent
printf '%s\n' '--- Named commit, if present locally ---'
git show --format=fuller --no-ext-diff --unified=30 28b3e21 -- openwisp-config/files/openwisp.agent 2>/dev/null || true
printf '%s\n' '--- register() context ---'
rg -n -A120 -B15 '^[[:space:]]*register\s*\(\)' openwisp-config/files/openwisp.agentLength of output: 11510 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- FETCH_COMMAND and proxy-related configuration/usages ---'
rg -n -i -C3 \
'(FETCH_COMMAND|https?_proxy|proxy[[:space:]_=-]|--proxy|CURLOPT_PROXY)' \
.
printf '%s\n' '--- Existing HTTP-status and response-header parsing ---'
rg -n -C3 \
'(is_http_status[[:space:]]|head[[:space:]]+-n[[:space:]]+1.*REGISTRATION_PARAMETERS|check_header[[:space:]])' \
openwisp-config/files/openwisp.agentLength of output: 9605
🐇 ✅ If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! ✅ Action performedReview finished.
|
Problem
During device registration the agent calls
check_header()before checkingthe HTTP status code. A transient server-side error (HTTP 5xx — e.g.
502/503/504returned by a reverse proxy while the backend is restarting) carries noX-Openwisp-Controllerheader, socheck_headertreats the response as comingfrom the wrong server and calls
exit 4.Combined with procd's respawn limit (
respawn ... 5), a short controller outagethat happens to overlap a (re)registration attempt makes procd give up
permanently after a few exits — leaving the agent dead until a manual
restart, even though the controller recovered seconds later.
The other three
check_headercall sites (get_checksum,update_info, statusreport) already guard with an
is_http_status ... 200check before callingcheck_header, so a 5xx there returns a retryable code. Only the registrationpath was missing this guard.
Fix
Treat a 5xx registration response as a temporary failure (
return 2, retryable)before
check_headerruns. Non-5xx responses still go throughcheck_header,preserving the existing "wrong server" safety (
exit 4) for a 2xx response thatlacks the controller header.
The
curl -ioutput that populates$REGISTRATION_PARAMETERSstarts with thestatus line (e.g.
HTTP/1.1 502 Bad Gateway), so the5[0-9][0-9]match isconsistent with how
is_http_statusreads the status elsewhere.Testing
shellcheck -s shonopenwisp.agent: clean.shfmtformat check: clean.curl -istatuslines:
502/503/504→ retry (return 2);200/201/403/404→ fallthrough to
check_headerunchanged.This is a small, self-contained change to the registration retry logic; the
existing non-5xx behaviour is preserved.