rpcclient: close the grpc.ClientConn on shutdown
This commit is contained in:
parent
3cda0a7cc4
commit
d257acee24
|
@ -50,7 +50,6 @@ import (
|
|||
"github.com/hashicorp/consul/lib/file"
|
||||
"github.com/hashicorp/consul/lib/mutex"
|
||||
"github.com/hashicorp/consul/logging"
|
||||
"github.com/hashicorp/consul/proto/pbsubscribe"
|
||||
"github.com/hashicorp/consul/tlsutil"
|
||||
"github.com/hashicorp/consul/types"
|
||||
)
|
||||
|
@ -386,7 +385,7 @@ func New(bd BaseDeps) (*Agent, error) {
|
|||
CacheName: cachetype.HealthServicesName,
|
||||
ViewStore: bd.ViewStore,
|
||||
MaterializerDeps: health.MaterializerDeps{
|
||||
Client: pbsubscribe.NewStateChangeSubscriptionClient(conn),
|
||||
Conn: conn,
|
||||
Logger: bd.Logger.Named("rpcclient.health"),
|
||||
},
|
||||
}
|
||||
|
@ -1393,6 +1392,8 @@ func (a *Agent) ShutdownAgent() error {
|
|||
a.cache.Close()
|
||||
}
|
||||
|
||||
a.rpcClientHealth.Close()
|
||||
|
||||
var err error
|
||||
if a.delegate != nil {
|
||||
err = a.delegate.Shutdown()
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/hashicorp/consul/agent/cache"
|
||||
"github.com/hashicorp/consul/agent/structs"
|
||||
"github.com/hashicorp/consul/agent/submatview"
|
||||
"github.com/hashicorp/consul/proto/pbsubscribe"
|
||||
)
|
||||
|
||||
// TODO: godoc
|
||||
|
@ -108,6 +109,14 @@ func (c *Client) newServiceRequest(req structs.ServiceSpecificRequest) serviceRe
|
|||
}
|
||||
}
|
||||
|
||||
// Close any underlying connections used by the client.
|
||||
func (c *Client) Close() error {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return c.MaterializerDeps.Conn.Close()
|
||||
}
|
||||
|
||||
type serviceRequest struct {
|
||||
structs.ServiceSpecificRequest
|
||||
deps MaterializerDeps
|
||||
|
@ -128,7 +137,7 @@ func (r serviceRequest) NewMaterializer() (*submatview.Materializer, error) {
|
|||
}
|
||||
return submatview.NewMaterializer(submatview.Deps{
|
||||
View: view,
|
||||
Client: r.deps.Client,
|
||||
Client: pbsubscribe.NewStateChangeSubscriptionClient(r.deps.Conn),
|
||||
Logger: r.deps.Logger,
|
||||
Request: newMaterializerRequest(r.ServiceSpecificRequest),
|
||||
}), nil
|
||||
|
|
|
@ -8,15 +8,15 @@ import (
|
|||
|
||||
"github.com/hashicorp/go-bexpr"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/hashicorp/consul/agent/structs"
|
||||
"github.com/hashicorp/consul/agent/submatview"
|
||||
"github.com/hashicorp/consul/proto/pbservice"
|
||||
"github.com/hashicorp/consul/proto/pbsubscribe"
|
||||
)
|
||||
|
||||
type MaterializerDeps struct {
|
||||
Client submatview.StreamClient
|
||||
Conn *grpc.ClientConn
|
||||
Logger hclog.Logger
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue