Skip to content

Commit

Permalink
resmgr,log,net: ditch unused gRPC helper bits.
Browse files Browse the repository at this point in the history
Since we're not a gRPC proxy any more, remove unused gRPC logger
and net helper bits.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
  • Loading branch information
klihub committed Oct 27, 2023
1 parent 4aa2596 commit 43fe36a
Showing 3 changed files with 0 additions and 240 deletions.
94 changes: 0 additions & 94 deletions pkg/log/grpc-logger.go

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/resmgr/main/main.go
Original file line number Diff line number Diff line change
@@ -74,8 +74,6 @@ func (m *Main) Run() error {
}

func (m *Main) setupLoggers() {
rate := logger.Rate{Limit: logger.Every(1 * time.Minute)}
logger.SetGrpcLogger("grpc", &rate)
logger.SetStdLogger("stdlog")
logger.SetupDebugToggleSignal(syscall.SIGUSR1)
}
144 changes: 0 additions & 144 deletions pkg/utils/net.go
Original file line number Diff line number Diff line change
@@ -16,85 +16,11 @@ package utils

import (
"errors"
"fmt"
"net"
"os"
"syscall"
"time"

"google.golang.org/grpc"
)

// WaitForServer waits for a gRPC server to start accepting connections on a socket.
func WaitForServer(socket string, timeout time.Duration, opts ...interface{}) error {
var errChecker []func(error) bool
var dialOpts []grpc.DialOption
var connp **grpc.ClientConn

for _, o := range opts {
switch o.(type) {
case func(error) bool:
errChecker = append(errChecker, o.(func(error) bool))
case grpc.DialOption:
dialOpts = append(dialOpts, o.(grpc.DialOption))
case []grpc.DialOption:
dialOpts = append(dialOpts, o.([]grpc.DialOption)...)
case **grpc.ClientConn:
if connp != nil {
return fmt.Errorf("WaitForServer: multiple net.Conn pointer options given")
}
connp = o.(**grpc.ClientConn)
default:
return fmt.Errorf("WaitForServer: invalid option of type %T", o)
}
}

if len(errChecker) < 1 {
errChecker = []func(error) bool{isFatalDialError}
}

if len(dialOpts) == 0 {
dialOpts = []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithBlock(),
grpc.FailOnNonTempDialError(true),
grpc.WithTimeout(timeout),
grpc.WithDialer(func(socket string, timeout time.Duration) (net.Conn, error) {
conn, err := net.Dial("unix", socket)
return conn, err
}),
}
}

start := time.Now()
for {
conn, err := grpc.Dial(socket, dialOpts...)
if err == nil {
if connp != nil {
*connp = conn
} else {
conn.Close()
}
return nil
}

for _, f := range errChecker {
if f(err) {
return err
}
}

switch {
case timeout >= 0 && start.Add(timeout).Before(time.Now()):
return err
case timeout < 0 || timeout > time.Second:
time.Sleep(time.Second)
default:
time.Sleep(timeout / 2)
}
}
}

// IsListeningSocket returns true if connections are accepted on the socket.
func IsListeningSocket(socket string) (bool, error) {
conn, err := net.Dial("unix", socket)
@@ -109,73 +35,3 @@ func IsListeningSocket(socket string) (bool, error) {

return false, err
}

// Check if a socket connection error looks fatal.
//
// Notes:
// Hmm... I wonder if it is really so difficult or I am just doing
// it wrong ? We would like to find out if a connection attempt to
// a unix-domain socket fails with a fatal error, in which case we
// don't want to stick around retrying it later.
//
// We treat errors which the originating layer considers a timeout
// or a temporary error as non-fatal one. Otherwise, we single out
// a few special errors:
// - EPERM: fatal error
// - EACCES: fatal error
// - ENOENT: non-fatal, server might still come around
// - ECONNREFUSED: non-fatal, maybe a lingering socket
//

type temporary interface {
Temporary() bool
}

type timeout interface {
Timeout() bool
}

type origin interface {
Origin() error
}

func isFatalDialError(err error) bool {
for {
if e, ok := err.(temporary); ok {
if e.Temporary() {
return false
}
}
if e, ok := err.(timeout); ok {
if e.Timeout() {
return false
}
}

switch err.(type) {
case *net.OpError:
err = err.(*net.OpError).Err
continue
case *os.SyscallError:
ne := err.(*os.SyscallError)
switch {
case os.IsPermission(ne):
return true
case os.IsNotExist(ne):
return false
case ne.Err == syscall.ECONNREFUSED:
return true
default:
err = ne
continue
}
default:
if oe, ok := err.(origin); ok {
err = oe.Origin()
continue
}
}

return true
}
}

0 comments on commit 43fe36a

Please sign in to comment.