Skip to content

Commit 5d07ac5

Browse files
committed
fix: close apid inter-backend connections gracefully for real
Fixes #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>
1 parent 7ba1855 commit 5d07ac5

File tree

1 file changed

+4
-1
lines changed
  • internal/app/apid/pkg/backend

1 file changed

+4
-1
lines changed

internal/app/apid/pkg/backend/apid.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
// GracefulShutdownTimeout is the timeout for graceful shutdown of the backend connection.
3131
//
3232
// Talos has a few long-running API calls, so we need to give the backend some time to finish them.
33+
//
34+
// The connection will enter IDLE time after GracefulShutdownTimeout/2, if no RPC is running.
3335
const GracefulShutdownTimeout = 30 * time.Minute
3436

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

276-
for ctx.Err() != nil {
279+
for ctx.Err() == nil {
277280
switch state := conn.GetState(); state { //nolint:exhaustive
278281
case connectivity.Idle,
279282
connectivity.Shutdown,

0 commit comments

Comments
 (0)