Skip to content

Commit

Permalink
fix(rpc): set const ReadHeaderTimeout to dymint RPC server (#671)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin authored Apr 17, 2024
1 parent df192a9 commit 4c05a1d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
38 changes: 22 additions & 16 deletions rpc/json/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ type unsubscribeArgs struct {
type unsubscribeAllArgs struct{}

// info API
type healthArgs struct{}
type statusArgs struct{}
type netInfoArgs struct{}
type blockchainInfoArgs struct {
MinHeight StrInt64 `json:"minHeight"`
MaxHeight StrInt64 `json:"maxHeight"`
}
type genesisArgs struct{}
type genesisChunkedArgs struct {
ID StrInt `json:"chunk"`
}
type (
healthArgs struct{}
statusArgs struct{}
netInfoArgs struct{}
blockchainInfoArgs struct {
MinHeight StrInt64 `json:"minHeight"`
MaxHeight StrInt64 `json:"maxHeight"`
}
)
type (
genesisArgs struct{}
genesisChunkedArgs struct {
ID StrInt `json:"chunk"`
}
)
type blockArgs struct {
Height StrInt64 `json:"height"`
}
Expand Down Expand Up @@ -67,11 +71,13 @@ type validatorsArgs struct {
Page StrInt `json:"page"`
PerPage StrInt `json:"per_page"`
}
type dumpConsensusStateArgs struct{}
type getConsensusStateArgs struct{}
type consensusParamsArgs struct {
Height StrInt64 `json:"height"`
}
type (
dumpConsensusStateArgs struct{}
getConsensusStateArgs struct{}
consensusParamsArgs struct {
Height StrInt64 `json:"height"`
}
)
type unconfirmedTxsArgs struct {
Limit StrInt `json:"limit"`
}
Expand Down
10 changes: 8 additions & 2 deletions rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ type Server struct {
}

const (
// DefaultServerTimeout is the default global timeout for the server.
// defaultServerTimeout is the time limit for handling HTTP requests.
defaultServerTimeout = 15 * time.Second

// ReadHeaderTimeout is the timeout for reading the request headers.
ReadHeaderTimeout = 5 * time.Second
)

// Option is a function that configures the Server.
Expand Down Expand Up @@ -197,7 +200,10 @@ func (s *Server) startRPC() error {

func (s *Server) serve(listener net.Listener, handler http.Handler) error {
s.Logger.Info("serving HTTP", "listen address", listener.Addr())
s.server = http.Server{Handler: handler} // #nosec
s.server = http.Server{
Handler: handler,
ReadHeaderTimeout: ReadHeaderTimeout,
}
if s.config.TLSCertFile != "" && s.config.TLSKeyFile != "" {
return s.server.ServeTLS(listener, s.config.CertFile(), s.config.KeyFile())
}
Expand Down

0 comments on commit 4c05a1d

Please sign in to comment.