mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-02 18:34:29 +08:00
fix: fix the timeout
This commit is contained in:
parent
482227552e
commit
38d3064399
@ -60,7 +60,7 @@ func Start(
|
|||||||
rpcTcpAddr,
|
rpcTcpAddr,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.Wrap(err, rpcTcpAddr)
|
return errs.Wrap(err, "rpc start err", rpcTcpAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
@ -118,7 +118,7 @@ func Start(
|
|||||||
// Create a HTTP server for prometheus.
|
// Create a HTTP server for prometheus.
|
||||||
httpServer = &http.Server{Handler: promhttp.HandlerFor(reg, promhttp.HandlerOpts{}), Addr: fmt.Sprintf("0.0.0.0:%d", prometheusPort)}
|
httpServer = &http.Server{Handler: promhttp.HandlerFor(reg, promhttp.HandlerOpts{}), Addr: fmt.Sprintf("0.0.0.0:%d", prometheusPort)}
|
||||||
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||||
netErr = errs.Wrap(err, "prometheus start err: ", httpServer.Addr)
|
netErr = errs.Wrap(err, "prometheus start err", httpServer.Addr)
|
||||||
close(netDone)
|
close(netDone)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,11 +134,12 @@ func Start(
|
|||||||
|
|
||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigs, syscall.SIGUSR1)
|
signal.Notify(sigs, syscall.SIGUSR1)
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
select {
|
select {
|
||||||
case <-sigs:
|
case <-sigs:
|
||||||
print("receive process terminal SIGUSR1 exit")
|
print("receive process terminal SIGUSR1 exit")
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||||
|
defer cancel()
|
||||||
if err := gracefulStopWithCtx(ctx, srv.GracefulStop); err != nil {
|
if err := gracefulStopWithCtx(ctx, srv.GracefulStop); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -162,7 +163,7 @@ func gracefulStopWithCtx(ctx context.Context, f func()) error {
|
|||||||
}()
|
}()
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return errs.Wrap(errors.New("timeout"), "ctx graceful stop")
|
return errs.Wrap(errors.New("timeout, ctx graceful stop"))
|
||||||
case <-done:
|
case <-done:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user