Skip to content

Commit

Permalink
fix: close apid inter-backend connections gracefully for real
Browse files Browse the repository at this point in the history
Fixes siderolabs#8552

This fixes up the previous fix where `for` condition was inverted, and
also updates the idle timeout, so that the transition to idle happens
before the timeout expires.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Apr 16, 2024
1 parent 7ba1855 commit 5d07ac5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/app/apid/pkg/backend/apid.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
// GracefulShutdownTimeout is the timeout for graceful shutdown of the backend connection.
//
// Talos has a few long-running API calls, so we need to give the backend some time to finish them.
//
// The connection will enter IDLE time after GracefulShutdownTimeout/2, if no RPC is running.
const GracefulShutdownTimeout = 30 * time.Minute

var _ proxy.Backend = (*APID)(nil)
Expand Down Expand Up @@ -106,6 +108,7 @@ func (a *APID) GetConnection(ctx context.Context, fullMethodName string) (contex
grpc.WithInitialWindowSize(65535*32),
grpc.WithInitialConnWindowSize(65535*16),
grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)),
grpc.WithIdleTimeout(GracefulShutdownTimeout/2), // use half of the shutdown timeout as idle timeout
grpc.WithConnectParams(grpc.ConnectParams{
Backoff: backoffConfig,
// not published as a constant in gRPC library
Expand Down Expand Up @@ -273,7 +276,7 @@ func gracefulGRPCClose(conn *grpc.ClientConn, timeout time.Duration) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

for ctx.Err() != nil {
for ctx.Err() == nil {
switch state := conn.GetState(); state { //nolint:exhaustive
case connectivity.Idle,
connectivity.Shutdown,
Expand Down

0 comments on commit 5d07ac5

Please sign in to comment.