Skip to content

agent: reconnect when every management server is in the avoid list - #14953

Open
brhellman wants to merge 1 commit into
apache:4.22from
brhellman:fix-10915-agent-avoid-list
Open

brhellman wants to merge 1 commit into
apache:4.22from
brhellman:fix-10915-agent-avoid-list

Conversation

@brhellman

Copy link
Copy Markdown

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 [4.21/main] CloudStack agent does not reconnect to management server #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)
  • 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
  • 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

An agent whose only configured management server is in its avoid list
never tries to reconnect: Agent.reconnect() skips every host in the
avoid list, sleeps and picks the same host again, forever, without
logging anything (apache#10915).

The avoid list comes with every ping answer from
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, for example after
a management server was re-installed with a new msid on the same
address, or when management servers share an address. The agents then
avoid the management server they are connected to and do not come back
after the next disconnect.

- listNonUpStateMsIPs() no longer returns an address an Up management
  server uses.
- When every configured management server is in the avoid list, the
  agent ignores the avoid list for that reconnect, and it logs a host it
  skips because it is in the avoid list.

Fixes apache#10915

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@boring-cyborg

boring-cyborg Bot commented Dec 2, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant