diff --git a/.pending/breaking/sdk/4263-RestServer-Star b/.pending/breaking/sdk/4263-RestServer-Star new file mode 100644 index 000000000000..23ebd5e68d4c --- /dev/null +++ b/.pending/breaking/sdk/4263-RestServer-Star @@ -0,0 +1 @@ +#4263 RestServer#Start now takes read and write timeout arguments. diff --git a/.pending/features/sdk/4263-Add---read-time b/.pending/features/sdk/4263-Add---read-time new file mode 100644 index 000000000000..50703a555740 --- /dev/null +++ b/.pending/features/sdk/4263-Add---read-time @@ -0,0 +1,2 @@ +#4263 Add `--read-timeout` and `--write-timeout` args to the `rest-server` command +to support custom RPC R/W timeouts. diff --git a/client/flags.go b/client/flags.go index 26ff68e82c23..cbd94e30a9f9 100644 --- a/client/flags.go +++ b/client/flags.go @@ -49,6 +49,8 @@ const ( FlagListenAddr = "laddr" FlagCORS = "cors" FlagMaxOpenConnections = "max-open" + FlagRPCReadTimeout = "read-timeout" + FlagRPCWriteTimeout = "write-timeout" FlagOutputDocument = "output-document" // inspired by wget -O FlagSkipConfirmation = "yes" ) @@ -116,7 +118,9 @@ func RegisterRestServerFlags(cmd *cobra.Command) *cobra.Command { cmd = GetCommands(cmd)[0] cmd.Flags().String(FlagListenAddr, "tcp://localhost:1317", "The address for the server to listen on") cmd.Flags().String(FlagCORS, "", "Set the domains that can make CORS requests (* for all)") - cmd.Flags().Int(FlagMaxOpenConnections, 1000, "The number of maximum open connections") + cmd.Flags().Uint(FlagMaxOpenConnections, 1000, "The number of maximum open connections") + cmd.Flags().Uint(FlagRPCReadTimeout, 10, "The RPC read timeout (in seconds)") + cmd.Flags().Uint(FlagRPCWriteTimeout, 10, "The RPC write timeout (in seconds)") return cmd } diff --git a/client/lcd/root.go b/client/lcd/root.go index 9325080e7002..bdeaf57bfbde 100644 --- a/client/lcd/root.go +++ b/client/lcd/root.go @@ -5,6 +5,7 @@ import ( "net" "net/http" "os" + "time" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" @@ -45,20 +46,22 @@ func NewRestServer(cdc *codec.Codec) *RestServer { Mux: r, CliCtx: cliCtx, Cdc: cdc, - - log: logger, + log: logger, } } // Start starts the rest server -func (rs *RestServer) Start(listenAddr string, maxOpen int) (err error) { +func (rs *RestServer) Start(listenAddr string, maxOpen int, readTimeout, writeTimeout uint) (err error) { server.TrapSignal(func() { err := rs.listener.Close() rs.log.Error("error closing listener", "err", err) }) - cfg := rpcserver.DefaultConfig() - cfg.MaxOpenConnections = maxOpen + cfg := &rpcserver.Config{ + MaxOpenConnections: maxOpen, + ReadTimeout: time.Duration(readTimeout) * time.Second, + WriteTimeout: time.Duration(writeTimeout) * time.Second, + } rs.listener, err = rpcserver.Listen(listenAddr, cfg) if err != nil { @@ -87,8 +90,12 @@ func ServeCommand(cdc *codec.Codec, registerRoutesFn func(*RestServer)) *cobra.C registerRoutesFn(rs) // Start the rest server and return error if one exists - err = rs.Start(viper.GetString(client.FlagListenAddr), - viper.GetInt(client.FlagMaxOpenConnections)) + err = rs.Start( + viper.GetString(client.FlagListenAddr), + viper.GetInt(client.FlagMaxOpenConnections), + uint(viper.GetInt(client.FlagRPCReadTimeout)), + uint(viper.GetInt(client.FlagRPCWriteTimeout)), + ) return err },