From 8d9acf57ade5af19913a97b6a178ed2599cb339f Mon Sep 17 00:00:00 2001 From: Woosang Son Date: Mon, 5 Apr 2021 15:31:02 +0900 Subject: [PATCH] feat: Add idle-timeout to rest server and rpc server config (#114) * feat: add to rest server * chore: fix test failure * chore: add changelog_pending including changes before releasing --- CHANGELOG_PENDING.md | 29 +++++++++++++++++++++++++++++ codec/types/any_test.go | 7 +++++++ server/api/server.go | 1 + server/config/config.go | 12 +++++++++--- server/config/toml.go | 9 ++++++--- 5 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 CHANGELOG_PENDING.md diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md new file mode 100644 index 0000000000..818b14f72b --- /dev/null +++ b/CHANGELOG_PENDING.md @@ -0,0 +1,29 @@ +# Unreleased Changes + +## lbm-sdk v2 + +Write the changes made after branching from cosmos-sdk v0.42.1. + +### BREAKING CHANGES + +- CLI/RPC/Config +* (rpc) [\#97](https://github.com/line/lbm-sdk/pull/97) Send response with 404 status when quering non-exist account + +- Apps + +- P2P Protocol + +- Go API +* (global) [\#90](https://github.com/line/lbm-sdk/pull/90) Rename module path to `github.com/line/lbm-sdk/v2` + +- Blockchain Protocol + +### FEATURES +* (global) [\#97](https://github.com/line/lbm-sdk/pull/97) Add codespace to response +* (global) [\#97](https://github.com/line/lbm-sdk/pull/97) Add codespace to query error +* (config) [\#114](https://github.com/line/lbm-sdk/pull/114) Add idle-timeout to rest server and rpc server config + +### IMPROVEMENTS + +### BUG FIXES + diff --git a/codec/types/any_test.go b/codec/types/any_test.go index f5ae3a1fd6..e6944b309e 100644 --- a/codec/types/any_test.go +++ b/codec/types/any_test.go @@ -3,6 +3,7 @@ package types_test import ( "fmt" "runtime" + "runtime/debug" "testing" "github.com/gogo/protobuf/proto" @@ -31,11 +32,17 @@ var eom = &errOnMarshal{} // See https://github.com/cosmos/cosmos-sdk/issues/8537 func TestNewAnyWithCustomTypeURLWithErrorNoAllocation(t *testing.T) { var ms1, ms2 runtime.MemStats + + debug.SetGCPercent(-1) // disable gc. See the comments below for reasons. runtime.ReadMemStats(&ms1) any, err := types.NewAnyWithCustomTypeURL(eom, fauxURL) runtime.ReadMemStats(&ms2) + debug.SetGCPercent(100) // resume gc // Ensure that no fresh allocation was made. if diff := ms2.HeapAlloc - ms1.HeapAlloc; diff > 0 { + // In some cases, `ms1.HeapAlloc` is larger than `ms2.HeapAlloc`. + // It is probably because the gc worked. + // That's why we turned off the gc for a while. t.Errorf("Unexpected allocation of %d bytes", diff) } if err == nil { diff --git a/server/api/server.go b/server/api/server.go index c549a5ccaa..0a998d48f7 100644 --- a/server/api/server.go +++ b/server/api/server.go @@ -97,6 +97,7 @@ func (s *Server) Start(cfg config.Config) error { ostCfg.MaxOpenConnections = int(cfg.API.MaxOpenConnections) ostCfg.ReadTimeout = time.Duration(cfg.API.RPCReadTimeout) * time.Second ostCfg.WriteTimeout = time.Duration(cfg.API.RPCWriteTimeout) * time.Second + ostCfg.IdleTimeout = time.Duration(cfg.API.RPCIdleTimeout) * time.Second ostCfg.MaxBodyBytes = int64(cfg.API.RPCMaxBodyBytes) listener, err := ostrpcserver.Listen(cfg.API.Address, ostCfg) diff --git a/server/config/config.go b/server/config/config.go index cd3c621970..d7c7f025f1 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -84,13 +84,16 @@ type APIConfig struct { // MaxOpenConnections defines the number of maximum open connections MaxOpenConnections uint `mapstructure:"max-open-connections"` - // RPCReadTimeout defines the Tendermint RPC read timeout (in seconds) + // RPCReadTimeout defines the Ostracon RPC read timeout (in seconds) RPCReadTimeout uint `mapstructure:"rpc-read-timeout"` - // RPCWriteTimeout defines the Tendermint RPC write timeout (in seconds) + // RPCWriteTimeout defines the Ostracon RPC write timeout (in seconds) RPCWriteTimeout uint `mapstructure:"rpc-write-timeout"` - // RPCMaxBodyBytes defines the Tendermint maximum response body (in bytes) + // RPCIdleTimeout defines the Ostracon RPC idle timeout (in seconds) + RPCIdleTimeout uint `mapstructure:"rpc-idle-timeout"` + + // RPCMaxBodyBytes defines the Ostracon maximum response body (in bytes) RPCMaxBodyBytes uint `mapstructure:"rpc-max-body-bytes"` // TODO: TLS/Proxy configuration. @@ -179,6 +182,8 @@ func DefaultConfig() *Config { Address: "tcp://0.0.0.0:1317", MaxOpenConnections: 1000, RPCReadTimeout: 10, + RPCWriteTimeout: 10, + RPCIdleTimeout: 60, RPCMaxBodyBytes: 1000000, }, GRPC: GRPCConfig{ @@ -232,6 +237,7 @@ func GetConfig(v *viper.Viper) Config { MaxOpenConnections: v.GetUint("api.max-open-connections"), RPCReadTimeout: v.GetUint("api.rpc-read-timeout"), RPCWriteTimeout: v.GetUint("api.rpc-write-timeout"), + RPCIdleTimeout: v.GetUint("api.rpc-idle-timeout"), RPCMaxBodyBytes: v.GetUint("api.rpc-max-body-bytes"), EnableUnsafeCORS: v.GetBool("api.enabled-unsafe-cors"), }, diff --git a/server/config/toml.go b/server/config/toml.go index 106821aa4b..537c2906f2 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -123,13 +123,16 @@ address = "{{ .API.Address }}" # MaxOpenConnections defines the number of maximum open connections. max-open-connections = {{ .API.MaxOpenConnections }} -# RPCReadTimeout defines the Tendermint RPC read timeout (in seconds). +# RPCReadTimeout defines the Ostracon RPC read timeout (in seconds). rpc-read-timeout = {{ .API.RPCReadTimeout }} -# RPCWriteTimeout defines the Tendermint RPC write timeout (in seconds). +# RPCWriteTimeout defines the Ostracon RPC write timeout (in seconds). rpc-write-timeout = {{ .API.RPCWriteTimeout }} -# RPCMaxBodyBytes defines the Tendermint maximum response body (in bytes). +# RPCIdleTimeout defines the Ostracon RPC idle timeout (in seconds). +rpc-idle-timeout = {{ .API.RPCIdleTimeout }} + +# RPCMaxBodyBytes defines the Ostracon maximum response body (in bytes). rpc-max-body-bytes = {{ .API.RPCMaxBodyBytes }} # EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk).