From 59bc4d65b89a2e22aa4ffac764603c3cba230173 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Tue, 13 Sep 2022 18:39:28 +0200 Subject: [PATCH 1/2] Fix HTTP server always force closing --- node/rpcstack.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/node/rpcstack.go b/node/rpcstack.go index 5d411fa61e81..b88719104f19 100644 --- a/node/rpcstack.go +++ b/node/rpcstack.go @@ -269,8 +269,7 @@ func (h *httpServer) doStop() { } ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout) defer cancel() - err := h.server.Shutdown(ctx) - if err == ctx.Err() { + if err := h.server.Shutdown(ctx); err != nil && err == ctx.Err() { h.log.Warn("HTTP server graceful shutdown timed out") h.server.Close() } From e03ffd5612518f6faa8419aeb0a8750dc9f1a671 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 13 Sep 2022 23:06:49 +0200 Subject: [PATCH 2/2] node: improve formattting --- node/rpcstack.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/node/rpcstack.go b/node/rpcstack.go index b88719104f19..f45435bab22d 100644 --- a/node/rpcstack.go +++ b/node/rpcstack.go @@ -267,12 +267,15 @@ func (h *httpServer) doStop() { h.wsHandler.Store((*rpcHandler)(nil)) wsHandler.server.Stop() } + ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout) defer cancel() - if err := h.server.Shutdown(ctx); err != nil && err == ctx.Err() { + err := h.server.Shutdown(ctx) + 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())