node: fix HTTP server always force closing (#25755)

Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Nicolas Gotchac 2022-09-14 18:37:53 +02:00 committed by GitHub
parent 9d717167aa
commit 25b35c9728
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -267,13 +267,15 @@ func (h *httpServer) doStop() {
h.wsHandler.Store((*rpcHandler)(nil))
wsHandler.server.Stop()
}
ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
defer cancel()
err := h.server.Shutdown(ctx)
if err == ctx.Err() {
if err != nil && err == ctx.Err() {
h.log.Warn("HTTP server graceful shutdown timed out")
h.server.Close()
}
h.listener.Close()
h.log.Info("HTTP server stopped", "endpoint", h.listener.Addr())