mirror of
https://github.com/status-im/consul.git
synced 2025-01-09 21:35:52 +00:00
Merge pull request #14935 from hashicorp/fix/alias-leak
This commit is contained in:
commit
ee4cdc4985
3
.changelog/14935.txt
Normal file
3
.changelog/14935.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
agent: avoid leaking the alias check runner goroutine when the check is de-registered
|
||||||
|
```
|
@ -3267,7 +3267,10 @@ func (a *Agent) cancelCheckMonitors(checkID structs.CheckID) {
|
|||||||
check.Stop()
|
check.Stop()
|
||||||
delete(a.checkH2PINGs, checkID)
|
delete(a.checkH2PINGs, checkID)
|
||||||
}
|
}
|
||||||
|
if check, ok := a.checkAliases[checkID]; ok {
|
||||||
|
check.Stop()
|
||||||
|
delete(a.checkAliases, checkID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateTTLCheck is used to update the status of a TTL check via the Agent API.
|
// updateTTLCheck is used to update the status of a TTL check via the Agent API.
|
||||||
|
@ -1912,7 +1912,7 @@ node_name = "` + a.Config.NodeName + `"
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAgent_AddCheck_Alias(t *testing.T) {
|
func TestAgent_Alias_AddRemove(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("too slow for testing.Short")
|
t.Skip("too slow for testing.Short")
|
||||||
}
|
}
|
||||||
@ -1922,29 +1922,39 @@ func TestAgent_AddCheck_Alias(t *testing.T) {
|
|||||||
a := NewTestAgent(t, "")
|
a := NewTestAgent(t, "")
|
||||||
defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
|
|
||||||
health := &structs.HealthCheck{
|
cid := structs.NewCheckID("aliashealth", nil)
|
||||||
Node: "foo",
|
|
||||||
CheckID: "aliashealth",
|
|
||||||
Name: "Alias health check",
|
|
||||||
Status: api.HealthCritical,
|
|
||||||
}
|
|
||||||
chk := &structs.CheckType{
|
|
||||||
AliasService: "foo",
|
|
||||||
}
|
|
||||||
err := a.AddCheck(health, chk, false, "", ConfigSourceLocal)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Ensure we have a check mapping
|
testutil.RunStep(t, "add check", func(t *testing.T) {
|
||||||
sChk := requireCheckExists(t, a, "aliashealth")
|
health := &structs.HealthCheck{
|
||||||
require.Equal(t, api.HealthCritical, sChk.Status)
|
Node: "foo",
|
||||||
|
CheckID: cid.ID,
|
||||||
|
Name: "Alias health check",
|
||||||
|
Status: api.HealthCritical,
|
||||||
|
}
|
||||||
|
chk := &structs.CheckType{
|
||||||
|
AliasService: "foo",
|
||||||
|
}
|
||||||
|
err := a.AddCheck(health, chk, false, "", ConfigSourceLocal)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
chkImpl, ok := a.checkAliases[structs.NewCheckID("aliashealth", nil)]
|
sChk := requireCheckExists(t, a, cid.ID)
|
||||||
require.True(t, ok, "missing aliashealth check")
|
require.Equal(t, api.HealthCritical, sChk.Status)
|
||||||
require.Equal(t, "", chkImpl.RPCReq.Token)
|
|
||||||
|
|
||||||
cs := a.State.CheckState(structs.NewCheckID("aliashealth", nil))
|
chkImpl, ok := a.checkAliases[cid]
|
||||||
require.NotNil(t, cs)
|
require.True(t, ok, "missing aliashealth check")
|
||||||
require.Equal(t, "", cs.Token)
|
require.Equal(t, "", chkImpl.RPCReq.Token)
|
||||||
|
|
||||||
|
cs := a.State.CheckState(cid)
|
||||||
|
require.NotNil(t, cs)
|
||||||
|
require.Equal(t, "", cs.Token)
|
||||||
|
})
|
||||||
|
|
||||||
|
testutil.RunStep(t, "remove check", func(t *testing.T) {
|
||||||
|
require.NoError(t, a.RemoveCheck(cid, false))
|
||||||
|
|
||||||
|
requireCheckMissing(t, a, cid.ID)
|
||||||
|
requireCheckMissingMap(t, a.checkAliases, cid.ID)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAgent_AddCheck_Alias_setToken(t *testing.T) {
|
func TestAgent_AddCheck_Alias_setToken(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user