mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-10-27 22:12:15 +08:00
fix: nil pointer error on close
This commit is contained in:
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"
|
||||||
@ -109,9 +108,8 @@ 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…
x
Reference in New Issue
Block a user