Skip to content

Commit

Permalink
feat: Add idle-timeout to rest server and rpc server config (#114)
Browse files Browse the repository at this point in the history
* feat: add  to rest server

* chore: fix test failure

* chore: add changelog_pending including changes before releasing
  • Loading branch information
Woosang Son authored Apr 5, 2021
1 parent 37fc9d1 commit 8d9acf5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions codec/types/any_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types_test
import (
"fmt"
"runtime"
"runtime/debug"
"testing"

"github.com/gogo/protobuf/proto"
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions server/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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"),
},
Expand Down
9 changes: 6 additions & 3 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down

0 comments on commit 8d9acf5

Please sign in to comment.