From 7bd39e6bf9109e40934f86695973ccad8c4a0887 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Sun, 3 Mar 2024 22:05:24 +0800 Subject: [PATCH] rpc: add http.TimeoutHandler for http server --- rpc/http.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rpc/http.go b/rpc/http.go index e43597a992..e7b90acbe3 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -237,11 +237,12 @@ func NewHTTPServer(cors []string, vhosts []string, srv *Server, writeTimeout tim // Wrap the CORS-handler within a host-handler handler := newCorsHandler(srv, cors) handler = newVHostHandler(vhosts, handler) + handler = http.TimeoutHandler(handler, writeTimeout, `{"error":"http server timeout"}`) log.Info("NewHTTPServer", "writeTimeout", writeTimeout) return &http.Server{ Handler: handler, ReadTimeout: 5 * time.Second, - WriteTimeout: writeTimeout, + WriteTimeout: writeTimeout + time.Second, IdleTimeout: 120 * time.Second, } }