brhellman opened a new pull request, #14953:
URL: https://github.com/apache/cloudstack/pull/14953

   ### Description
   
   This PR fixes agents that never reconnect after their connection to the 
management server drops, when the address they connect to is in their avoid 
list (#10915).
   
   `Agent.reconnect()` skips every host that is in the avoid list. When every 
configured host is in it — for example `host=<one address>` — it sleeps and 
picks the same host again, forever, without logging anything; the agent stays 
Disconnected until it is restarted.
   
   The avoid list comes with every ping answer: 
`ManagementServerHostDaoImpl.listNonUpStateMsIPs()`, the service IPs of all 
management servers that are not `Up`. A management server that is not `Up` can 
share its service IP with one that is `Up` — a management server re-installed 
with a new msid on the same address, or management servers sharing an address — 
so the agents are told to avoid the management server they are connected to.
   
   Changes:
   - `listNonUpStateMsIPs()` no longer returns an address that an `Up` 
management server uses.
   - `Agent.reconnect()`: when every configured management server is in the 
avoid list, the avoid list is ignored for that reconnect (WARN logged), and a 
host skipped because it is in the avoid list is logged at INFO. This also 
covers the graceful-shutdown case described in #10915.
   
   Fixes: #10915
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [x] Bug fix (non-breaking change which fixes an issue)
   - [ ] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   - [ ] Build/CI
   - [ ] Test (unit or integration test code)
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Bug Severity
   
   - [ ] BLOCKER
   - [ ] Critical
   - [x] Major
   - [ ] Minor
   - [ ] Trivial
   
   ### How Has This Been Tested?
   
   **Unit tests** (JDK 17, Maven 3.9.16, `mvn -B -T 32 -Dnoredist -pl 
agent,framework/cluster -am 
-Dtest="AgentTest,AgentShellTest,ManagementServerHostDaoImplTest,ClusterManagerImplTest"
 -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false install`, BUILD 
SUCCESS, 0 checkstyle violations):
   - new `ManagementServerHostDaoImplTest` — 3/3: excludes addresses of Up 
management servers; keeps addresses no Up server uses; does not query Up 
servers when all are Up.
   - `AgentTest` — 26/26, 3 new: avoid list ignored when it holds every 
configured host (and the WARN is logged); kept when another host is available; 
no avoid list.
   - existing `AgentShellTest` 24/24, `ClusterManagerImplTest` 1/1.
   - The same commit cherry-picked onto tag `4.23.0.0` builds and passes 
`AgentTest` 26/26 and `ManagementServerHostDaoImplTest` 3/3.
   
   **On a real cluster** (CloudStack 4.23.0.0 RPMs, AlmaLinux 10.3, one 
management server, four KVM hosts, LINSTOR primary storage). The patched 
classes were built from this commit cherry-picked onto `4.23.0.0` and swapped 
into `cloud-agent-4.23.0.0.jar` / `cloudstack-4.23.0.0.jar`. Setup: the 
management server's `cluster.node.IP` is the address in the `host` setting (the 
agents' only management server). Each scenario: insert a second `mshost` row in 
state `Down` with that service IP (what a management server re-installed with a 
new msid on the same address leaves behind), wait one ping round, then cut the 
agents' connections to 8250 with `ss -K`.
   
   | # | Management server | Agents | Result |
   |---|---|---|---|
   | 1 | 4.23.0.0 | 4.23.0.0 | **reproduced**: 0/4 hosts Up 5 min after the 
cut; each agent logged `Lost connection to host: … Attempting reconnection 
while we still have 0 commands in progress.` and nothing after |
   | 2 | with this fix | 4.23.0.0 | all 4 hosts reconnected (~2 min) |
   | 3 | 4.23.0.0 | with this fix | all 4 hosts reconnected (~2 min); agent 
log: `WARN … All configured management servers [10.20.20.80] are in the avoid 
list [10.20.20.80], ignoring the avoid list to reconnect` → `Reconnecting to 
host` → `Connected to the host` |
   | 4 | 4.23.0.0, graceful `systemctl restart cloudstack-management` (the case 
in #10915) | with this fix | all 4 hosts reconnected |
   
   We first hit this with three management servers behind one virtual IP (one 
active at a time) where every server had the VIP as `cluster.node.IP`: after 
the active server's node was powered off, the agents on the surviving hosts 
stayed Disconnected for 18 minutes until restarted (thread dump in #10915).
   
   #### How did you try to break this feature and the system with this change?
   
   - Agent with several configured management servers, one of them in the avoid 
list: still skipped (unit test).
   - No avoid list: unchanged behaviour (unit test).
   - Several management servers, one of them really down with its own address: 
still in the avoid list (`ManagementServerHostDaoImplTest`; only addresses that 
an `Up` server also uses are dropped).
   
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] agent: reconnect when eve... brhellman (via GitHub) via commits

Reply via email to