`PUT /agent/force-leave` endpoint returns status code 500 instead of 404 on missing node
- Dominant language
- Go
- Stars
- 30.1k
- Forks
- 4.6k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 39
Description
#### Overview of the Issue
The `PUT /agent/force-leave/:node_name` HTTP endpoint responds with a `500 Internal Server Error` instead of `404 Not Found` when there is no node with the specified name.
---
#### Reproduction Steps
1. Start a consul server with version 1.19.1
1. Run `curl --verbose --request PUT /v1/agent/force-leave/nonexistent-node`
1. See that response code is 500
### Consul info for both Client and Server
Client info
N/A
Server info
```
# consul info
agent:
check_monitors = 0
check_ttls = 0
checks = 0
services = 0
build:
prerelease =
revision = bf0166d8
version = 1.19.0
version_metadata =
consul:
acl = disabled
bootstrap = true
known_datacenters = 1
leader = true
leader_addr = 172.17.0.2:8300
server = true
raft:
applied_index = 14
commit_index = 14
fsm_pending = 0
last_contact = 0
last_log_index = 14
last_log_term = 2
last_snapshot_index = 0
last_snapshot_term = 0
latest_configuration = [{Suffrage:Voter ID:a245377a-5061-3dc6-e7bf-10cf775b2027 Address:172.17.0.2:8300}]
latest_configuration_index = 0
num_peers = 0
protocol_version = 3
protocol_version_max = 3
protocol_version_min = 0
snapshot_version_max = 1
snapshot_version_min = 0
state = Leader
term = 2
runtime:
arch = amd64
cpu_count = 12
goroutines = 185
max_procs = 12
os = linux
version = go1.22.4
serf_lan:
coordinate_resets = 0
encrypted = false
event_queue = 1
event_time = 2
failed = 0
health_score = 0
intent_queue = 0
left = 0
member_time = 1
members = 1
query_queue = 0
query_time = 1
serf_wan:
coordinate_resets = 0
encrypted = false
event_queue = 0
event_time = 1
failed = 0
health_score = 0
intent_queue = 0
left = 0
member_time = 1
members = 1
query_queue = 0
query_time = 1
```
HCL:
```
data_dir = "/consul/data"
server = true
bootstrap = true
```
### Operating system and Environment details
OS: Arch linux (kernel version 6.10.12-hardened1-1-hardened)
This happens for Consul 1.19.1 when run both in docker and on bare-metal
### Log Fragments
```
2024-10-28T12:36:59.145Z [INFO] agent: Force leaving node: node=this-node-does-not-exist
2024-10-28T12:36:59.145Z [WARN] agent: Failed to remove node: node=this-node-does-not-exist error="agent: No node found with name 'this-node-does-not-exist'"
2024-10-28T12:36:59.145Z [ERROR] agent.http: Request error: method=PUT url=/v1/agent/force-leave/this-node-does-not-exist from=172.17.0.1:36870 error="agent: No node found with name 'this-node-does-not-exist'"
2024-10-28T12:36:59.145Z [DEBUG] agent.http: Request finished: method=PUT url=/v1/agent/force-leave/this-node-does-not-exist from=172.17.0.1:36870 latency="94.995µs"
```
Contributor guide
Research direction
Start by locating the Go HTTP handler for PUT /v1/agent/force-leave/:node_name and reproduce the missing-node request with curl. Trace how the reported "No node found" error is mapped to an HTTP response, then add or update coverage so the endpoint returns 404 instead of 500.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100