Skip to content

Commit

Permalink
disable disconnection during non-IP-direct connection (#2291)
Browse files Browse the repository at this point in the history
Signed-off-by: kpango <kpango@vdaas.org>
Co-authored-by: Yusuke Kadowaki <yusuke.kadowaki.1231@gmail.com>
  • Loading branch information
kpango and ykadowak authored Jan 10, 2024
1 parent 3ef2f35 commit ac50bf3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 17 additions & 4 deletions internal/net/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ func (g *gRPCClient) StartConnectionMonitor(ctx context.Context) (<-chan error,
disconnectTargets = append(disconnectTargets, addr)
return true
}
// for health check we don't need to reconnect when ip connection pool is healthy
if p.IsHealthy(ctx) && p.IsIPConn() {
// for health check we don't need to reconnect when connection is healthy
if p.IsHealthy(ctx) {
return true
}
// if connection is not ip direct or unhealthy let's re-connect
Expand Down Expand Up @@ -329,9 +329,22 @@ func (g *gRPCClient) StartConnectionMonitor(ctx context.Context) (<-chan error,
}
})
cancel()
disconnected := make(map[string]bool, len(disconnectTargets))
var (
disconnectFlag bool
isIPv4, isIPv6 bool
host string
port uint16
disconnected = make(map[string]bool, len(disconnectTargets))
)
for _, addr := range disconnectTargets {
if !disconnected[addr] {
host, port, _, isIPv4, isIPv6, err = net.Parse(addr)
disconnectFlag = isIPv4 || isIPv6 // Disconnect only if the connection is a direct IP connection; do not delete connections via DNS due to retry.
if err != nil {
log.Warnf("failed to parse addr %s for disconnection checking, will disconnect soon: host: %s, port %d, err: %v", addr, host, port, err)
disconnectFlag = true // Disconnect if the address connected to is not parseable.
}
if disconnectFlag &&
!disconnected[addr] {
err = g.Disconnect(ctx, addr)
if err != nil {
if !errors.Is(err, context.Canceled) &&
Expand Down
6 changes: 3 additions & 3 deletions internal/net/grpc/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (p *pool) connect(ctx context.Context, ips ...string) (c Conn, err error) {
!errors.Is(ierr, context.Canceled) {
log.Warnf("An error occurred while dialing pool member connection to %s,\terror: %v", addr, ierr)
} else {
log.Debug("Connect loop operation canceled while dialing pool member connection to %s,\terror: %v", addr, ierr)
log.Debugf("Connect loop operation canceled while dialing pool member connection to %s,\terror: %v", addr, ierr)
return false
}
}
Expand Down Expand Up @@ -421,7 +421,7 @@ func (p *pool) singleTargetConnect(ctx context.Context) (c Conn, err error) {
}
return true
} else {
log.Debug("Connect loop operation canceled while dialing pool member connection to %s,\terror: %v", p.addr, ierr)
log.Debugf("Connect loop operation canceled while dialing pool member connection to %s,\terror: %v", p.addr, ierr)
return false
}
}
Expand Down Expand Up @@ -449,7 +449,7 @@ func (p *pool) Disconnect() (err error) {
log.Debugf("failed to close connection pool addr = %s\terror = %v", pc.addr, ierr)
emap[ierr.Error()] = err
} else {
log.Debug("Disconnect loop operation canceled while closing pool member connection to %s,\terror: %v", pc.addr, ierr)
log.Debugf("Disconnect loop operation canceled while closing pool member connection to %s,\terror: %v", pc.addr, ierr)
return false
}
}
Expand Down

0 comments on commit ac50bf3

Please sign in to comment.