Skip to content

Commit

Permalink
Make RPC timeout configurable (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Jun 24, 2024
1 parent 8484212 commit fbf3097
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ type RPCConfig struct {

// Lag threshold determines the threshold for whether the /lag_status endpoint returns OK or not
LagThreshold int64 `mapstructure:"lag-threshold"`

// Timeout for any read request
TimeoutRead time.Duration `mapstructure:"timeout-read"`
}

// DefaultRPCConfig returns a default configuration for the RPC server
Expand Down Expand Up @@ -547,6 +550,8 @@ func DefaultRPCConfig() *RPCConfig {
TLSCertFile: "",
TLSKeyFile: "",
LagThreshold: 300,

TimeoutRead: 10 * time.Second,
}
}

Expand Down
3 changes: 3 additions & 0 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ tls-key-file = "{{ .RPC.TLSKeyFile }}"
# pprof listen address (https://golang.org/pkg/net/http/pprof)
pprof-laddr = "{{ .RPC.PprofListenAddress }}"
# timeout for any read request
timeout-read = "{{ .RPC.TimeoutRead }}"
#######################################################
### P2P Configuration Options ###
#######################################################
Expand Down
4 changes: 4 additions & 0 deletions internal/rpc/core/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ func (env *Environment) StartService(ctx context.Context, conf *config.Config) (
cfg.WriteTimeout = conf.RPC.TimeoutBroadcastTxCommit + 1*time.Second
}

if conf.RPC.TimeoutRead > 0 {
cfg.ReadTimeout = conf.RPC.TimeoutRead
}

// If the event log is enabled, subscribe to all events published to the
// event bus, and forward them to the event log.
if lg := env.EventLog; lg != nil {
Expand Down

0 comments on commit fbf3097

Please sign in to comment.