Make http server timeouts configurable for cli commands

This commit is contained in:
Geoff Stuart 2022-11-25 17:32:42 -05:00
parent e6e50ee9f7
commit 1f70ced8e5
7 changed files with 77 additions and 8 deletions

View File

@ -74,6 +74,10 @@ var runCmd = &cli.Command{
Name: "captcha-threshold",
Value: 0.5,
},
&cli.StringFlag{
Name: "http-server-timeout",
Value: "3s",
},
},
Action: func(cctx *cli.Context) error {
sendPerRequest, err := types.ParseFIL(cctx.String("amount"))
@ -127,9 +131,14 @@ var runCmd = &cli.Command{
os.Exit(0)
}()
timeout, err := time.ParseDuration(cctx.String("http-server-timeout"))
if err != nil {
return xerrors.Errorf("invalid time string %s: %x", cctx.String("http-server-timeout"), err)
}
server := &http.Server{
Addr: cctx.String("front"),
ReadHeaderTimeout: 3 * time.Second,
ReadHeaderTimeout: timeout,
}
return server.ListenAndServe()

View File

@ -418,12 +418,21 @@ var runCmd = &cli.Command{
Usage: "messages with a prove cap larger than this will be skipped when processing pre commit messages",
Value: "0.000000001",
},
&cli.StringFlag{
Name: "http-server-timeout",
Value: "3s",
},
},
Action: func(cctx *cli.Context) error {
timeout, err := time.ParseDuration(cctx.String("http-server-timeout"))
if err != nil {
return xerrors.Errorf("invalid time string %s: %x", cctx.String("http-server-timeout"), err)
}
go func() {
server := &http.Server{
Addr: ":6060",
ReadHeaderTimeout: 3 * time.Second,
ReadHeaderTimeout: timeout,
}
_ = server.ListenAndServe()

View File

@ -26,6 +26,10 @@ var itestdCmd = &cli.Command{
Name: "listen",
Value: "127.0.0.1:5674",
},
&cli.StringFlag{
Name: "http-server-timeout",
Value: "3s",
},
},
Action: func(cctx *cli.Context) error {
var nodes []kit.ItestdNotif
@ -45,9 +49,14 @@ var itestdCmd = &cli.Command{
if err != nil {
return xerrors.Errorf("net listen: %w", err)
}
timeout, err := time.ParseDuration(cctx.String("http-server-timeout"))
if err != nil {
return xerrors.Errorf("invalid time string %s: %x", cctx.String("http-server-timeout"), err)
}
s := &httptest.Server{
Listener: l,
Config: &http.Server{Handler: m, ReadHeaderTimeout: 3 * time.Second},
Config: &http.Server{Handler: m, ReadHeaderTimeout: timeout},
}
s.Start()
fmt.Printf("ITest env:\n\nLOTUS_ITESTD=%s\n\nSay 'sh' to spawn a shell connected to test nodes\n--- waiting for clients\n", s.URL)

View File

@ -6,6 +6,8 @@ import (
"sort"
"time"
"golang.org/x/xerrors"
"contrib.go.opencensus.io/exporter/prometheus"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
@ -76,8 +78,14 @@ type msgInfo struct {
var mpoolStatsCmd = &cli.Command{
Name: "mpool-stats",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "http-server-timeout",
Value: "3s",
},
},
Action: func(cctx *cli.Context) error {
logging.SetLogLevel("rpc", "ERROR")
_ = logging.SetLogLevel("rpc", "ERROR")
if err := view.Register(AgeView, SizeView, InboundRate, InclusionRate, MsgWait); err != nil {
return err
@ -92,10 +100,15 @@ var mpoolStatsCmd = &cli.Command{
http.Handle("/debug/metrics", expo)
timeout, err := time.ParseDuration(cctx.String("http-server-timeout"))
if err != nil {
return xerrors.Errorf("invalid time string %s: %x", cctx.String("http-server-timeout"), err)
}
go func() {
server := &http.Server{
Addr: ":10555",
ReadHeaderTimeout: 3 * time.Second,
ReadHeaderTimeout: timeout,
}
if err := server.ListenAndServe(); err != nil {

View File

@ -7,6 +7,8 @@ import (
"os"
"time"
"golang.org/x/xerrors"
"contrib.go.opencensus.io/exporter/prometheus"
logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2"
@ -128,6 +130,10 @@ var runCmd = &cli.Command{
EnvVars: []string{"LOTUS_STATS_IPLD_STORE_CACHE_SIZE"},
Value: 2 << 15,
},
&cli.StringFlag{
Name: "http-server-timeout",
Value: "3s",
},
},
Action: func(cctx *cli.Context) error {
ctx := context.Background()
@ -158,11 +164,16 @@ var runCmd = &cli.Command{
return err
}
timeout, err := time.ParseDuration(cctx.String("http-server-timeout"))
if err != nil {
return xerrors.Errorf("invalid time string %s: %x", cctx.String("http-server-timeout"), err)
}
go func() {
http.Handle("/metrics", exporter)
server := &http.Server{
Addr: ":6688",
ReadHeaderTimeout: 3 * time.Second,
ReadHeaderTimeout: timeout,
}
if err := server.ListenAndServe(); err != nil {
log.Errorw("failed to start http server", "err", err)

View File

@ -143,6 +143,10 @@ var runCmd = &cli.Command{
Usage: "(insecure) disable api auth",
Hidden: true,
},
&cli.StringFlag{
Name: "http-server-timeout",
Value: "3s",
},
},
Description: "Needs FULLNODE_API_INFO env-var to be set before running (see lotus-wallet --help for setup instructions)",
Action: func(cctx *cli.Context) error {
@ -240,9 +244,14 @@ var runCmd = &cli.Command{
}
}
timeout, err := time.ParseDuration(cctx.String("http-server-timeout"))
if err != nil {
return xerrors.Errorf("invalid time string %s: %x", cctx.String("http-server-timeout"), err)
}
srv := &http.Server{
Handler: handler,
ReadHeaderTimeout: 3 * time.Second,
ReadHeaderTimeout: timeout,
BaseContext: func(listener net.Listener) context.Context {
ctx, _ := tag.New(context.Background(), tag.Upsert(metrics.APIInterface, "lotus-wallet"))
return ctx

View File

@ -272,6 +272,10 @@ var runCmd = &cli.Command{
Value: "30m",
EnvVars: []string{"LOTUS_WORKER_TIMEOUT"},
},
&cli.StringFlag{
Name: "http-server-timeout",
Value: "3s",
},
},
Before: func(cctx *cli.Context) error {
if cctx.IsSet("address") {
@ -562,9 +566,14 @@ var runCmd = &cli.Command{
log.Info("Setting up control endpoint at " + address)
timeout, err := time.ParseDuration(cctx.String("http-server-timeout"))
if err != nil {
return xerrors.Errorf("invalid time string %s: %x", cctx.String("http-server-timeout"), err)
}
srv := &http.Server{
Handler: sealworker.WorkerHandler(nodeApi.AuthVerify, remoteHandler, workerApi, true),
ReadHeaderTimeout: 3 * time.Second,
ReadHeaderTimeout: timeout,
BaseContext: func(listener net.Listener) context.Context {
ctx, _ := tag.New(context.Background(), tag.Upsert(metrics.APIInterface, "lotus-worker"))
return ctx