From d2b7c3889bb479d76d4edbe71d3b6f24e57d6552 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Fri, 25 Nov 2022 16:24:09 -0500 Subject: [PATCH] Add more timeouts --- cmd/lotus-wallet/main.go | 4 +++- cmd/lotus-worker/main.go | 3 ++- node/rpc.go | 4 +++- testplans/lotus-soup/testkit/role_client.go | 2 +- testplans/lotus-soup/testkit/role_miner.go | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/lotus-wallet/main.go b/cmd/lotus-wallet/main.go index 75d31da56..a6662f75f 100644 --- a/cmd/lotus-wallet/main.go +++ b/cmd/lotus-wallet/main.go @@ -6,6 +6,7 @@ import ( "net" "net/http" "os" + "time" "github.com/gbrlsnchs/jwt/v3" "github.com/gorilla/mux" @@ -240,7 +241,8 @@ var runCmd = &cli.Command{ } srv := &http.Server{ - Handler: handler, + Handler: handler, + ReadHeaderTimeout: 3 * time.Second, BaseContext: func(listener net.Listener) context.Context { ctx, _ := tag.New(context.Background(), tag.Upsert(metrics.APIInterface, "lotus-wallet")) return ctx diff --git a/cmd/lotus-worker/main.go b/cmd/lotus-worker/main.go index afee6f1e1..e4e80cad0 100644 --- a/cmd/lotus-worker/main.go +++ b/cmd/lotus-worker/main.go @@ -563,7 +563,8 @@ var runCmd = &cli.Command{ log.Info("Setting up control endpoint at " + address) srv := &http.Server{ - Handler: sealworker.WorkerHandler(nodeApi.AuthVerify, remoteHandler, workerApi, true), + Handler: sealworker.WorkerHandler(nodeApi.AuthVerify, remoteHandler, workerApi, true), + ReadHeaderTimeout: 3 * time.Second, BaseContext: func(listener net.Listener) context.Context { ctx, _ := tag.New(context.Background(), tag.Upsert(metrics.APIInterface, "lotus-worker")) return ctx diff --git a/node/rpc.go b/node/rpc.go index 96a81a383..2dc00e863 100644 --- a/node/rpc.go +++ b/node/rpc.go @@ -9,6 +9,7 @@ import ( _ "net/http/pprof" "runtime" "strconv" + "time" "github.com/google/uuid" "github.com/gorilla/mux" @@ -51,7 +52,8 @@ func ServeRPC(h http.Handler, id string, addr multiaddr.Multiaddr) (StopFunc, er // Instantiate the server and start listening. srv := &http.Server{ - Handler: h, + Handler: h, + ReadHeaderTimeout: 3 * time.Second, BaseContext: func(listener net.Listener) context.Context { ctx, _ := tag.New(context.Background(), tag.Upsert(metrics.APIInterface, id)) return ctx diff --git a/testplans/lotus-soup/testkit/role_client.go b/testplans/lotus-soup/testkit/role_client.go index afde27420..7cd0e4c4a 100644 --- a/testplans/lotus-soup/testkit/role_client.go +++ b/testplans/lotus-soup/testkit/role_client.go @@ -182,7 +182,7 @@ func startFullNodeAPIServer(t *TestEnvironment, repo repo.Repo, napi api.FullNod Next: mux.ServeHTTP, } - srv := &http.Server{Handler: ah} + srv := &http.Server{Handler: ah, ReadHeaderTimeout: 3 * time.Second} endpoint, err := repo.APIEndpoint() if err != nil { diff --git a/testplans/lotus-soup/testkit/role_miner.go b/testplans/lotus-soup/testkit/role_miner.go index 3b74a50cb..1eb405714 100644 --- a/testplans/lotus-soup/testkit/role_miner.go +++ b/testplans/lotus-soup/testkit/role_miner.go @@ -638,7 +638,7 @@ func startStorageMinerAPIServer(t *TestEnvironment, repo repo.Repo, minerApi api return nil, fmt.Errorf("no API endpoint in repo: %w", err) } - srv := &http.Server{Handler: ah} + srv := &http.Server{Handler: ah, ReadHeaderTimeout: 3 * time.Second} listenAddr, err := startServer(endpoint, srv) if err != nil {