diff --git a/consul/fsm.go b/consul/fsm.go index 78d8226eea..f603f53ea1 100644 --- a/consul/fsm.go +++ b/consul/fsm.go @@ -46,6 +46,11 @@ func NewFSM(logOutput io.Writer) (*consulFSM, error) { return fsm, nil } +// Close is used to cleanup resources associated with the FSM +func (c *consulFSM) Close() error { + return c.state.Close() +} + // State is used to return a handle to the current state func (c *consulFSM) State() *StateStore { return c.state diff --git a/consul/fsm_test.go b/consul/fsm_test.go index 1c2745bb2f..ea94eb6d29 100644 --- a/consul/fsm_test.go +++ b/consul/fsm_test.go @@ -40,6 +40,7 @@ func TestFSM_RegisterNode(t *testing.T) { if err != nil { t.Fatalf("err: %v", err) } + defer fsm.Close() req := structs.RegisterRequest{ Datacenter: "dc1", @@ -75,6 +76,7 @@ func TestFSM_RegisterNode_Service(t *testing.T) { if err != nil { t.Fatalf("err: %v", err) } + defer fsm.Close() req := structs.RegisterRequest{ Datacenter: "dc1", @@ -127,6 +129,7 @@ func TestFSM_DeregisterService(t *testing.T) { if err != nil { t.Fatalf("err: %v", err) } + defer fsm.Close() req := structs.RegisterRequest{ Datacenter: "dc1", @@ -181,6 +184,7 @@ func TestFSM_DeregisterCheck(t *testing.T) { if err != nil { t.Fatalf("err: %v", err) } + defer fsm.Close() req := structs.RegisterRequest{ Datacenter: "dc1", @@ -235,6 +239,7 @@ func TestFSM_DeregisterNode(t *testing.T) { if err != nil { t.Fatalf("err: %v", err) } + defer fsm.Close() req := structs.RegisterRequest{ Datacenter: "dc1", @@ -301,6 +306,7 @@ func TestFSM_SnapshotRestore(t *testing.T) { if err != nil { t.Fatalf("err: %v", err) } + defer fsm.Close() // Add some state fsm.state.EnsureNode(1, structs.Node{"foo", "127.0.0.1"}) @@ -336,6 +342,7 @@ func TestFSM_SnapshotRestore(t *testing.T) { if err != nil { t.Fatalf("err: %v", err) } + defer fsm2.Close() // Do a restore if err := fsm2.Restore(sink); err != nil { diff --git a/consul/server.go b/consul/server.go index 63ee805906..7ad58fee7c 100644 --- a/consul/server.go +++ b/consul/server.go @@ -336,6 +336,9 @@ func (s *Server) Shutdown() error { // Close the connection pool s.connPool.Shutdown() + // Close the fsm + s.fsm.Close() + return nil }