Skip to content

Commit 2e4252e

Browse files
committed
force stop
1 parent d1714f6 commit 2e4252e

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

flyteadmin/pkg/server/service.go

+13-14
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func serveGatewayInsecure(ctx context.Context, pluginRegistry *plugins.Registry,
390390

391391
go func() {
392392
if err := grpcServer.Serve(lis); err != nil {
393-
logger.Fatalf(ctx, "Failed to create GRPC Server, Err: ", err)
393+
logger.Fatalf(ctx, "Failed to create GRPC Server, Err: %v", err)
394394
}
395395
}()
396396

@@ -437,22 +437,21 @@ func serveGatewayInsecure(ctx context.Context, pluginRegistry *plugins.Registry,
437437
sigCh := make(chan os.Signal, 1)
438438
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
439439
<-sigCh
440+
time.Sleep(1 * time.Second)
440441

441-
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
442-
defer cancel()
443-
444-
if err := server.Shutdown(shutdownCtx); err != nil {
445-
logger.Errorf(ctx, "Failed to shutdown HTTP server: %v", err)
446-
}
442+
// force to shut down servers after 10 seconds
443+
timer := time.AfterFunc(10 * time.Second, func() {
444+
logger.Infof(ctx, "Server couldn't stop gracefully in time. Doing force stop.")
445+
server.Close()
446+
grpcServer.Stop()
447+
})
448+
defer timer.Stop()
447449

448-
grpcShutdownCtx, grpcCancel := context.WithTimeout(context.Background(), 10*time.Second)
449-
defer grpcCancel()
450+
grpcServer.GracefulStop()
450451

451-
go func() {
452-
grpcServer.GracefulStop()
453-
grpcCancel()
454-
}()
455-
<-grpcShutdownCtx.Done()
452+
if err := server.Shutdown(ctx); err != nil {
453+
logger.Errorf(ctx, "Failed to gracefully shutdown HTTP server: %v", err)
454+
}
456455

457456
logger.Infof(ctx, "Servers gracefully stopped")
458457
return nil

0 commit comments

Comments
 (0)