Consul agent SIGTERM sometimes hangs
- Dominant language
- Go
- Stars
- 30.1k
- Forks
- 4.6k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 39
Description
When filing a bug, please include the following headings if possible. Any example text in this template can be deleted.
#### Overview of the Issue
I noticed a node had disappeared from Consul. Having a closer look at the box, it looks like Consul was attempted to be restarted on the host by sending a SIGTERM to Consul, but Consul did not quit.
#### Reproduction Steps
Sending SIGTERM to a running Consul agent. Note attempts to reproduce this on the same host after forcibly killing Consul with SIGKILL did not reproduce the issue.
### Consul info for both Client and Server
Client info
```
agent:
check_monitors = 0
check_ttls = 1
checks = 61
services = 62
build:
prerelease =
revision = 7bbad6fe
version = 1.10.4
consul:
acl = enabled
known_servers = 3
server = false
runtime:
arch = amd64
cpu_count = 4
goroutines = 497
max_procs = 4
os = linux
version = go1.16.10
serf_lan:
coordinate_resets = 0
encrypted = true
event_queue = 0
event_time = 962
failed = 0
health_score = 0
intent_queue = 0
left = 0
member_time = 106534
members = 168
query_queue = 0
query_time = 12
```
### Operating system and Environment details
Alpine Linux 3.15
### Log Fragments
```
2022-02-01T15:45:16.619Z [INFO] agent.client.memberlist.lan: memberlist: Suspect fintstoradb has failed, no acks received
2022-02-01T15:51:25.153Z [INFO] agent: Caught: signal=terminated
2022-02-01T15:51:25.153Z [INFO] agent: Gracefully shutting down agent...
2022-02-01T15:51:25.153Z [INFO] agent.client: client starting leave
2022-02-01T15:51:25.858Z [INFO] agent.client.serf.lan: serf: EventMemberLeave: nomad-worker-3 10.x.x.x
2022-02-01T15:51:29.619Z [INFO] agent: Graceful exit completed
2022-02-01T15:51:29.619Z [INFO] agent: Requesting shutdown
2022-02-01T15:51:45.030Z [ERROR] agent.client: RPC failed to server: method=Session.Apply server=10.x.x.243:8300 error="rpc error making call: rpc error making call: apply failed: Missing node registration"
2022-02-01T15:51:45.038Z [ERROR] agent.http: Request error: method=PUT url=/v1/session/create from=172.18.0.5:34908 error="rpc error making call: rpc error making call: apply failed: Missing node registration"
2022-02-01T15:51:45.302Z [ERROR] agent.client: RPC failed to server: method=Session.Apply server=10.x.x.241:8300 error="rpc error making call: rpc error making call: apply failed: Missing node registration"
2022-02-01T15:51:45.302Z [ERROR] agent.http: Request error: method=PUT url=/v1/session/create from=172.18.0.13:37236 error="rpc error making call: rpc error making call: apply failed: Missing node registration"
2022-02-01T15:51:46.404Z [ERROR] agent.client: RPC failed to server: method=Session.Apply server=10.x.x.242:8300 error="rpc error making call: apply failed: Missing node registration"
2022-02-01T15:51:46.404Z [ERROR] agent.http: Request error: method=PUT url=/v1/session/create from=172.18.0.26:35110 error="rpc error making call: apply failed: Missing node registration"
2022-02-01T15:52:03.435Z [ERROR] agent.client: RPC failed to server: method=Session.Apply server=10.x.x.243:8300 error="rpc error making call: rpc error making call: apply failed: Missing node registration"
2022-02-01T15:52:03.435Z [ERROR] agent.http: Request error: method=PUT url=/v1/session/create from=172.18.0.5:34910 error="rpc error making call: rpc error making call: apply failed: Missing node registration"
2022-02-01T15:52:03.904Z [ERROR] agent.client: RPC failed to server: method=Session.Apply server=10.x.x.241:8300 error="rpc error making call: rpc error making call: apply failed: Missing node registration"
2022-02-01T15:52:03.904Z [ERROR] agent.http: Request error: method=PUT url=/v1/session/create from=172.18.0.13:37238 error="rpc error making call: rpc error making call: apply failed: Missing node registration"
2022-02-01T15:52:05.192Z [ERROR] agent.client: RPC failed to server: method=Session.Apply server=10.x.x.242:8300 error="rpc error making call: apply failed: Missing node registration"
2022-02-01T15:52:05.192Z [ERROR] agent.http: Request error: method=PUT url=/v1/session/create from=172.18.0.5:34912 error="rpc error making call: apply failed: Missing node registration"
```
Of interest after doing a SIGKILL and attempting to reproduce the issue by sending a SIGTERM to a newly restarted Consul client, the shutdown logs when it worked had an additional log line after "agent: Requesting shutdown" which was not present in the hung Consul log:
```
2022-02-02T00:20:32.840Z [INFO] agent.client: shutting down client
```
I imagine however that is triggered is the source of it hanging. Perhaps a race condition since it doesn't seem easily reproducible.
Contributor guide
Research direction
No source file or test is named. Start by tracing the SIGTERM handler through the agent's graceful shutdown and the client shutdown path, comparing the hung log with the successful restart log. Done means the intermittent hang is reproduced or explained and shutdown reliably completes after SIGTERM, with regression coverage if the relevant test location is found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100