zeromicro / go-zero

A cloud-native Go microservices framework with cli tool for productivity.
https://go-zero.dev
MIT License
29.34k stars 3.96k forks source link

Graceful shutdown on windows #4460

Closed Han1enG closed 4 hours ago

Han1enG commented 1 day ago

Hello author. Is it true that graceful shutdown does not work on Windows platform? I found the corresponding logic in Linux or Darwin in the code.

image

My scenario is on Windows platform. I hope that when receiving the termination signal, the cached log will be saved to the file before exiting. But in fact, the program is terminated immediately.

func main() {
    flag.Parse()

    var c config.Config
    conf.MustLoad(*configFile, &c)
    server := rest.MustNewServer(c.RestConf, rest.WithCors())
    Init()
    server.Use(middleware.AuthInterceptor)
    server.Use(middleware.GlobalExceptionMiddleware)
    ctx := svc.NewServiceContext(c)
    handler.RegisterHandlers(server, ctx)

    group := service.NewServiceGroup()
    defer group.Stop()
    group.Add(&ws.WebSocketService{})
    group.Add(server)
    logx.Info("Starting http server at:", c.Host, c.Port)
    waitForCalled := proc.AddShutdownListener(func() {
        // ...save cached logs to file before exiting
    })
    group.Start()
    waitForCalled()
}

Looking forward to your reply, thank you

kevwan commented 17 hours ago

It's by design, we don't have a plan to support it on Windows.

Han1enG commented 4 hours ago

It's by design, we don't have a plan to support it on Windows.

Thanks for your reply.