From 832ffefde100e35b1217a87188eaf22f5d31c9e8 Mon Sep 17 00:00:00 2001 From: parthshah1 Date: Wed, 27 Aug 2025 10:51:04 -0400 Subject: [PATCH 1/2] fix(rpc): Adding read, write and idle timeout to rpc handler --- node/rpc.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/node/rpc.go b/node/rpc.go index 45154e7ac40..85eff2a02f9 100644 --- a/node/rpc.go +++ b/node/rpc.go @@ -47,7 +47,11 @@ func ServeRPC(h http.Handler, id string, addr multiaddr.Multiaddr) (StopFunc, er // Instantiate the server and start listening. srv := &http.Server{ Handler: h, - ReadHeaderTimeout: 30 * time.Second, + ReadHeaderTimeout: 10 * time.Second, + ReadTimeout: 60 * time.Second, + WriteTimeout: 60 * time.Second, + IdleTimeout: 60 * time.Second, + MaxHeaderBytes: 1 << 20, BaseContext: func(listener net.Listener) context.Context { ctx := context.Background() ctx = metrics.AddNetworkTag(ctx) From a46b2092872ae990297ce1caeee4e0145bb01a51 Mon Sep 17 00:00:00 2001 From: parthshah1 Date: Wed, 27 Aug 2025 11:09:39 -0400 Subject: [PATCH 2/2] adding the values as constants --- node/rpc.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/node/rpc.go b/node/rpc.go index 85eff2a02f9..08bc063c4c7 100644 --- a/node/rpc.go +++ b/node/rpc.go @@ -31,6 +31,15 @@ import ( var rpclog = logging.Logger("rpc") +const ( + // HTTP server timeout constants + readHeaderTimeout = 10 * time.Second + readTimeout = 60 * time.Second + writeTimeout = 60 * time.Second + idleTimeout = 60 * time.Second + maxHeaderBytes = 1 << 20 +) + // ServeRPC serves an HTTP handler over the supplied listen multiaddr. // // This function spawns a goroutine to run the server, and returns immediately. @@ -47,11 +56,11 @@ func ServeRPC(h http.Handler, id string, addr multiaddr.Multiaddr) (StopFunc, er // Instantiate the server and start listening. srv := &http.Server{ Handler: h, - ReadHeaderTimeout: 10 * time.Second, - ReadTimeout: 60 * time.Second, - WriteTimeout: 60 * time.Second, - IdleTimeout: 60 * time.Second, - MaxHeaderBytes: 1 << 20, + ReadHeaderTimeout: readHeaderTimeout, + ReadTimeout: readTimeout, + WriteTimeout: writeTimeout, + IdleTimeout: idleTimeout, + MaxHeaderBytes: maxHeaderBytes, BaseContext: func(listener net.Listener) context.Context { ctx := context.Background() ctx = metrics.AddNetworkTag(ctx)