mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
parent
a347ff7839
commit
30e0bfe71e
1 changed files with 12 additions and 1 deletions
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/log"
|
"github.com/XinFinOrg/XDPoSChain/log"
|
||||||
"github.com/XinFinOrg/XDPoSChain/rpc"
|
"github.com/XinFinOrg/XDPoSChain/rpc"
|
||||||
|
|
@ -88,6 +89,10 @@ type httpServer struct {
|
||||||
handlerNames map[string]string
|
handlerNames map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
shutdownTimeout = 5 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
func newHTTPServer(log log.Logger, timeouts rpc.HTTPTimeouts) *httpServer {
|
func newHTTPServer(log log.Logger, timeouts rpc.HTTPTimeouts) *httpServer {
|
||||||
h := &httpServer{log: log, timeouts: timeouts, handlerNames: make(map[string]string)}
|
h := &httpServer{log: log, timeouts: timeouts, handlerNames: make(map[string]string)}
|
||||||
h.httpHandler.Store((*rpcHandler)(nil))
|
h.httpHandler.Store((*rpcHandler)(nil))
|
||||||
|
|
@ -270,7 +275,13 @@ func (h *httpServer) doStop() {
|
||||||
h.wsHandler.Store((*rpcHandler)(nil))
|
h.wsHandler.Store((*rpcHandler)(nil))
|
||||||
wsHandler.server.Stop()
|
wsHandler.server.Stop()
|
||||||
}
|
}
|
||||||
h.server.Shutdown(context.Background())
|
ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
|
||||||
|
defer cancel()
|
||||||
|
err := h.server.Shutdown(ctx)
|
||||||
|
if err == ctx.Err() {
|
||||||
|
h.log.Warn("HTTP server graceful shutdown timed out")
|
||||||
|
h.server.Close()
|
||||||
|
}
|
||||||
h.listener.Close()
|
h.listener.Close()
|
||||||
h.log.Info("HTTP server stopped", "endpoint", h.listener.Addr())
|
h.log.Info("HTTP server stopped", "endpoint", h.listener.Addr())
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue