From 280e56f4bb16fcca91c4e66984ecad71779efd8f Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 25 Oct 2022 09:48:02 +0300 Subject: [PATCH] [#1893] neofs-node: Do not fail unless all gRPC endpoints are unavailable Signed-off-by: Evgenii Stratonikov --- CHANGELOG.md | 1 + cmd/neofs-node/control.go | 6 +++++- cmd/neofs-node/grpc.go | 25 +++++++++++++++++++------ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a7144c8f..4967b944b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Changelog for NeoFS Node - `neofs-adm` now works correctly with a committee of more than 4 nodes (#1949, #1959) - Closing a shard now waits until GC background workers stop (#1964) - Make it possible to use `shard.ContainerSize` in read-only mode (#1975) +- Storage node now starts if at least one gRPC enpoint is available (#1893) ### Removed ### Updated diff --git a/cmd/neofs-node/control.go b/cmd/neofs-node/control.go index f9d3c0aa5..02ece79da 100644 --- a/cmd/neofs-node/control.go +++ b/cmd/neofs-node/control.go @@ -9,6 +9,7 @@ import ( controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server" "github.com/nspcc-dev/neofs-node/pkg/services/tree" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + "go.uber.org/zap" "google.golang.org/grpc" ) @@ -50,7 +51,10 @@ func initControlService(c *cfg) { ) lis, err := net.Listen("tcp", endpoint) - fatalOnErr(err) + if err != nil { + c.log.Error("can't listen gRPC endpoint (control)", zap.Error(err)) + return + } c.cfgControlService.server = grpc.NewServer() diff --git a/cmd/neofs-node/grpc.go b/cmd/neofs-node/grpc.go index b60d4c2b8..c5e0f9c9e 100644 --- a/cmd/neofs-node/grpc.go +++ b/cmd/neofs-node/grpc.go @@ -2,6 +2,7 @@ package main import ( "crypto/tls" + "errors" "fmt" "net" "time" @@ -14,12 +15,8 @@ import ( ) func initGRPC(c *cfg) { + var successCount int grpcconfig.IterateEndpoints(c.appCfg, func(sc *grpcconfig.Config) { - lis, err := net.Listen("tcp", sc.Endpoint()) - fatalOnErr(err) - - c.cfgGRPC.listeners = append(c.cfgGRPC.listeners, lis) - serverOpts := []grpc.ServerOption{ grpc.MaxSendMsgSize(maxMsgSize), } @@ -28,7 +25,10 @@ func initGRPC(c *cfg) { if tlsCfg != nil { cert, err := tls.LoadX509KeyPair(tlsCfg.CertificateFile(), tlsCfg.KeyFile()) - fatalOnErrDetails("could not read certificate from file", err) + if err != nil { + c.log.Error("could not read certificate from file", zap.Error(err)) + return + } var cipherSuites []uint16 if !tlsCfg.UseInsecureCrypto() { @@ -54,6 +54,14 @@ func initGRPC(c *cfg) { serverOpts = append(serverOpts, grpc.Creds(creds)) } + lis, err := net.Listen("tcp", sc.Endpoint()) + if err != nil { + c.log.Error("can't listen gRPC endpoint", zap.Error(err)) + return + } + + c.cfgGRPC.listeners = append(c.cfgGRPC.listeners, lis) + srv := grpc.NewServer(serverOpts...) c.onShutdown(func() { @@ -61,7 +69,12 @@ func initGRPC(c *cfg) { }) c.cfgGRPC.servers = append(c.cfgGRPC.servers, srv) + successCount++ }) + + if successCount == 0 { + fatalOnErr(errors.New("could not listen to any gRPC endpoints")) + } } func serveGRPC(c *cfg) {