Skip to content

Commit

Permalink
disable disconnection during non-IP-direct connection (#2288)
Browse files Browse the repository at this point in the history
Signed-off-by: kpango <[email protected]>
  • Loading branch information
kpango authored and ykadowak committed Jan 10, 2024
1 parent 861274e commit 6c8f33d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 15 additions & 2 deletions internal/net/grpc/client.go
Original file line number Diff line number Diff line change
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))
)

Check warning on line 338 in internal/net/grpc/client.go

View check run for this annotation

Codecov / codecov/patch

internal/net/grpc/client.go#L332-L338

Added lines #L332 - L338 were not covered by tests
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] {

Check warning on line 347 in internal/net/grpc/client.go

View check run for this annotation

Codecov / codecov/patch

internal/net/grpc/client.go#L340-L347

Added lines #L340 - L347 were not covered by tests
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)

Check warning on line 362 in internal/net/grpc/pool/pool.go

View check run for this annotation

Codecov / codecov/patch

internal/net/grpc/pool/pool.go#L362

Added line #L362 was not covered by tests
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)

Check warning on line 424 in internal/net/grpc/pool/pool.go

View check run for this annotation

Codecov / codecov/patch

internal/net/grpc/pool/pool.go#L424

Added line #L424 was not covered by tests
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)

Check warning on line 452 in internal/net/grpc/pool/pool.go

View check run for this annotation

Codecov / codecov/patch

internal/net/grpc/pool/pool.go#L452

Added line #L452 was not covered by tests
return false
}
}
Expand Down

0 comments on commit 6c8f33d

Please sign in to comment.