Skip to content

Commit d9d3775

Browse files
committed
chore: change api agteway server context
Signed-off-by: Alessandro Yuichi Okimoto <yuichijpn@gmail.com>
1 parent 1d75ac9 commit d9d3775

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

manifests/bucketeer/charts/api/templates/deployment.yaml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,7 @@ spec:
184184
- /bin/sh
185185
- -c
186186
- |
187-
admin_port={{ .Values.envoy.adminPort }}
188-
max_wait=60
189-
190-
# Wait for active requests to drain
191-
for i in $(seq 1 "$max_wait"); do
192-
active=$(wget -q -O- "http://localhost:${admin_port}/stats" 2>/dev/null | grep "http.ingress_http.downstream_rq_active" | awk '{print $2}' || echo "0")
193-
[ -z "$active" ] && active=0
194-
[ "$active" -eq 0 ] && break
195-
sleep 1
196-
done
187+
sleep 60
197188
exit 0
198189
command: ["envoy"]
199190
args:

pkg/api/cmd/server.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func (s *server) Run(ctx context.Context, metrics metrics.Metrics, logger *zap.L
388388
if err != nil {
389389
return err
390390
}
391-
defer auditLogClient.Close()
391+
defer autoOpsClient.Close()
392392

393393
tagClient, err := tagclient.NewClient(*s.tagService, *s.certPath,
394394
client.WithPerRPCCredentials(creds),
@@ -502,7 +502,7 @@ func (s *server) Run(ctx context.Context, metrics metrics.Metrics, logger *zap.L
502502
// We don't check the Redis health status because if the check fails,
503503
// the Kubernetes will restart the container and it might cause internal errors.
504504
// Use a dedicated context so we can stop the health checker goroutine cleanly during shutdown
505-
healthCheckCtx, healthCheckCancel := context.WithCancel(ctx)
505+
healthCheckCtx, healthCheckCancel := context.WithCancel(context.Background())
506506
defer healthCheckCancel() // Ensure cleanup on all paths (including early returns)
507507

508508
healthChecker := health.NewGrpcChecker(
@@ -545,7 +545,9 @@ func (s *server) Run(ctx context.Context, metrics metrics.Metrics, logger *zap.L
545545
return fmt.Errorf("failed to create API gateway: %v", err)
546546
}
547547

548-
if err := apiGateway.Start(ctx, gatewayHandler); err != nil {
548+
serverCtx, serverCtxCancel := context.WithCancel(context.Background())
549+
defer serverCtxCancel()
550+
if err := apiGateway.Start(serverCtx, gatewayHandler); err != nil {
549551
return fmt.Errorf("failed to start API gateway: %v", err)
550552
}
551553

@@ -589,8 +591,6 @@ func (s *server) Run(ctx context.Context, metrics metrics.Metrics, logger *zap.L
589591
zap.Duration("wait_before_unready", waitBeforeUnready))
590592
time.Sleep(waitBeforeUnready)
591593

592-
// Cancel the health checker goroutines to prevent connection errors during shutdown
593-
healthCheckCancel()
594594
// Mark as unhealthy so readiness probes fail
595595
// This ensures Kubernetes readiness probe fails on next check,
596596
// preventing new traffic from being routed to this pod.
@@ -627,6 +627,10 @@ func (s *server) Run(ctx context.Context, metrics metrics.Metrics, logger *zap.L
627627
// Now it's safe to stop the gRPC server (no more HTTP→gRPC calls)
628628
server.Stop(grpcStopTimeout)
629629

630+
// Cancel goroutines
631+
healthCheckCancel()
632+
serverCtxCancel()
633+
630634
// Close clients
631635
// These are fast cleanup operations that can run asynchronously.
632636
go goalPublisher.Stop()

0 commit comments

Comments
 (0)