fix: nil pointer error on close

pull/2618/head
withchao 1 year ago
parent 59d606c75b
commit f7f0af24ec

@ -35,7 +35,6 @@ import (
"github.com/openimsdk/tools/errs" "github.com/openimsdk/tools/errs"
"github.com/openimsdk/tools/log" "github.com/openimsdk/tools/log"
"github.com/openimsdk/tools/mw" "github.com/openimsdk/tools/mw"
"github.com/openimsdk/tools/system/program"
"github.com/openimsdk/tools/utils/network" "github.com/openimsdk/tools/utils/network"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
@ -111,7 +110,6 @@ func Start[T any](ctx context.Context, discovery *config.Discovery, prometheusCo
var ( var (
netDone = make(chan struct{}, 2) netDone = make(chan struct{}, 2)
netErr error netErr error
httpServer *http.Server
) )
if prometheusConfig.Enable { if prometheusConfig.Enable {
go func() { go func() {
@ -148,18 +146,11 @@ func Start[T any](ctx context.Context, discovery *config.Discovery, prometheusCo
signal.Notify(sigs, syscall.SIGTERM) signal.Notify(sigs, syscall.SIGTERM)
select { select {
case <-sigs: case <-sigs:
program.SIGTERMExit() ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel() defer cancel()
if err := gracefulStopWithCtx(ctx, srv.GracefulStop); err != nil { if err := gracefulStopWithCtx(ctx, srv.GracefulStop); err != nil {
return err return err
} }
ctx, cancel = context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
err := httpServer.Shutdown(ctx)
if err != nil {
return errs.WrapMsg(err, "shutdown err")
}
return nil return nil
case <-netDone: case <-netDone:
return netErr return netErr

Loading…
Cancel
Save