[#1270] neofs-node: Add timeout for grpc GracefulStop()
GracefulStop() may be blocked until all server-side streams are finished. There is no control over such streams yet, so application may be frozen in shutdown stage. Naive solution is to add timeout for GracefulStop(). At this point healthy connection will be finished and unhealthy connections will be terminated by Stop(). Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
ad92493b86
commit
683439970a
1 changed files with 14 additions and 1 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"time"
|
||||||
|
|
||||||
grpcconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/grpc"
|
grpcconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/grpc"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
|
@ -95,7 +96,19 @@ func stopGRPC(name string, s *grpc.Server, l *logger.Logger) {
|
||||||
|
|
||||||
l.Info("stopping gRPC server...")
|
l.Info("stopping gRPC server...")
|
||||||
|
|
||||||
s.GracefulStop()
|
// GracefulStop() may freeze forever, see #1270
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
s.GracefulStop()
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
case <-time.After(1 * time.Minute):
|
||||||
|
l.Info("gRPC cannot shutdown gracefully, forcing stop")
|
||||||
|
s.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
l.Info("gRPC server stopped successfully")
|
l.Info("gRPC server stopped successfully")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue