mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
parent
94b3ca1eeb
commit
2ce0a220a2
5 changed files with 28 additions and 4 deletions
|
|
@ -147,6 +147,7 @@ var (
|
|||
utils.HTTPListenAddrFlag,
|
||||
utils.HTTPPortFlag,
|
||||
utils.HTTPReadTimeoutFlag,
|
||||
utils.HTTPReadHeaderTimeoutFlag,
|
||||
utils.HTTPWriteTimeoutFlag,
|
||||
utils.HTTPIdleTimeoutFlag,
|
||||
utils.HTTPApiFlag,
|
||||
|
|
|
|||
|
|
@ -476,6 +476,12 @@ var (
|
|||
Value: rpc.DefaultHTTPTimeouts.ReadTimeout,
|
||||
Category: flags.APICategory,
|
||||
}
|
||||
HTTPReadHeaderTimeoutFlag = &cli.DurationFlag{
|
||||
Name: "http-readheadertimeout",
|
||||
Usage: "HTTP-RPC server read timeout",
|
||||
Value: rpc.DefaultHTTPTimeouts.ReadHeaderTimeout,
|
||||
Category: flags.APICategory,
|
||||
}
|
||||
HTTPWriteTimeoutFlag = &cli.DurationFlag{
|
||||
Name: "http-writetimeout",
|
||||
Aliases: []string{"rpcwritetimeout"},
|
||||
|
|
@ -999,6 +1005,9 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
|
|||
if ctx.IsSet(HTTPReadTimeoutFlag.Name) {
|
||||
cfg.HTTPTimeouts.ReadTimeout = ctx.Duration(HTTPReadTimeoutFlag.Name)
|
||||
}
|
||||
if ctx.IsSet(HTTPReadHeaderTimeoutFlag.Name) {
|
||||
cfg.HTTPTimeouts.ReadHeaderTimeout = ctx.Duration(HTTPReadHeaderTimeoutFlag.Name)
|
||||
}
|
||||
if ctx.IsSet(HTTPWriteTimeoutFlag.Name) {
|
||||
cfg.HTTPTimeouts.WriteTimeout = ctx.Duration(HTTPWriteTimeoutFlag.Name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@ func CheckTimeouts(timeouts *rpc.HTTPTimeouts) {
|
|||
log.Warn("Sanitizing invalid HTTP read timeout", "provided", timeouts.ReadTimeout, "updated", rpc.DefaultHTTPTimeouts.ReadTimeout)
|
||||
timeouts.ReadTimeout = rpc.DefaultHTTPTimeouts.ReadTimeout
|
||||
}
|
||||
if timeouts.ReadHeaderTimeout < time.Second {
|
||||
log.Warn("Sanitizing invalid HTTP read header timeout", "provided", timeouts.ReadHeaderTimeout, "updated", rpc.DefaultHTTPTimeouts.ReadHeaderTimeout)
|
||||
timeouts.ReadHeaderTimeout = rpc.DefaultHTTPTimeouts.ReadHeaderTimeout
|
||||
}
|
||||
if timeouts.WriteTimeout < 2*time.Second {
|
||||
log.Warn("Sanitizing invalid HTTP write timeout", "provided", timeouts.WriteTimeout, "updated", rpc.DefaultHTTPTimeouts.WriteTimeout)
|
||||
timeouts.WriteTimeout = rpc.DefaultHTTPTimeouts.WriteTimeout
|
||||
|
|
|
|||
|
|
@ -125,10 +125,11 @@ func (h *httpServer) start() error {
|
|||
h.server = &http.Server{Handler: h}
|
||||
if h.timeouts != (rpc.HTTPTimeouts{}) {
|
||||
h.server.ReadTimeout = h.timeouts.ReadTimeout
|
||||
h.server.ReadHeaderTimeout = h.timeouts.ReadHeaderTimeout
|
||||
h.server.WriteTimeout = h.timeouts.WriteTimeout
|
||||
h.server.IdleTimeout = h.timeouts.IdleTimeout
|
||||
}
|
||||
log.Info("Start http server", "ReadTimeout", h.server.ReadTimeout, "WriteTimeout", h.server.WriteTimeout, "IdleTimeout", h.server.IdleTimeout)
|
||||
log.Info("Start http server", "ReadTimeout", h.server.ReadTimeout, "ReadHeaderTimeout", h.server.ReadHeaderTimeout, "WriteTimeout", h.server.WriteTimeout, "IdleTimeout", h.server.IdleTimeout)
|
||||
// Start the server.
|
||||
listener, err := net.Listen("tcp", h.endpoint)
|
||||
if err != nil {
|
||||
|
|
|
|||
15
rpc/http.go
15
rpc/http.go
|
|
@ -87,6 +87,14 @@ type HTTPTimeouts struct {
|
|||
// ReadHeaderTimeout. It is valid to use them both.
|
||||
ReadTimeout time.Duration
|
||||
|
||||
// ReadHeaderTimeout is the amount of time allowed to read
|
||||
// request headers. The connection's read deadline is reset
|
||||
// after reading the headers and the Handler can decide what
|
||||
// is considered too slow for the body. If ReadHeaderTimeout
|
||||
// is zero, the value of ReadTimeout is used. If both are
|
||||
// zero, there is no timeout.
|
||||
ReadHeaderTimeout time.Duration
|
||||
|
||||
// WriteTimeout is the maximum duration before timing out
|
||||
// writes of the response. It is reset whenever a new
|
||||
// request's header is read. Like ReadTimeout, it does not
|
||||
|
|
@ -103,9 +111,10 @@ type HTTPTimeouts struct {
|
|||
// DefaultHTTPTimeouts represents the default timeout values used if further
|
||||
// configuration is not provided.
|
||||
var DefaultHTTPTimeouts = HTTPTimeouts{
|
||||
ReadTimeout: 30 * time.Second,
|
||||
WriteTimeout: 30 * time.Second,
|
||||
IdleTimeout: 120 * time.Second,
|
||||
ReadTimeout: 30 * time.Second,
|
||||
ReadHeaderTimeout: 30 * time.Second,
|
||||
WriteTimeout: 30 * time.Second,
|
||||
IdleTimeout: 120 * time.Second,
|
||||
}
|
||||
|
||||
// DialHTTPWithClient creates a new RPC client that connects to an RPC server over HTTP
|
||||
|
|
|
|||
Loading…
Reference in a new issue