Skip to content

Return 404 from force-leave for nodes that are not cluster members - #24082

Open
Sanjays2402 wants to merge 2 commits into
hashicorp:mainfrom
Sanjays2402:fix-force-leave-unknown-node-404
Open

Sanjays2402 wants to merge 2 commits into
hashicorp:mainfrom
Sanjays2402:fix-force-leave-unknown-node-404

Conversation

@Sanjays2402

Copy link
Copy Markdown

Description

PUT /v1/agent/force-leave/<node> answered 500 when the named node did not exist. Both the client and the server remove paths already detected this case and produced a "No node found" error, but nothing set it apart from a genuine server failure, so the HTTP layer fell back to 500.

This adds a small sentinel error in agent/consul for the not-found case, keeps the existing error text exactly as it was, and has the force-leave handler translate it into a 404 carrying the same message. The WAN path goes through the same handler, so it gets the same treatment.

Testing & Reproduction steps

Repro: start a single agent and run curl -X PUT <addr>/v1/agent/force-leave/nonexistent-node. Before this change the response was 500; after, it is 404 with agent: No node found with name 'nonexistent-node'.

Added TestAgent_ForceLeave_UnknownNode, which drives the handler the same way the existing force-leave tests do and expects a 404. The existing force-leave tests still pass: TestAgent_ForceLeave, TestAgent_ForceLeave_ACLDeny, TestAgent_ForceLeavePrune, and TestAgent_ForceLeavePrune_WAN.

Links

Fixes #21878

Note: the changelog entry follows as .changelog/<PR number>.txt in a follow-up commit on this branch, since the file has to be named after the PR number.

PR Checklist

  • updated test coverage
  • external facing docs updated (not needed, this only corrects the status code for an existing endpoint)
  • appropriate backport labels added
  • not a security concern

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I've documented the impact of any changes to security controls.

@Sanjays2402
Sanjays2402 requested review from a team as code owners October 28, 2026 02:47
@hashicorp-cla-app

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

1 similar comment
@hashicorp-cla-app

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PUT /agent/force-leave endpoint returns status code 500 instead of 404 on missing node

1 participant