Fix 408 Timeout error returned by REST server. (#3301)

* Disable REST server timeouts.
* Add options to CLI to tune REST server parameters.
This commit is contained in:
Eugene Kabanov 2022-01-27 18:41:05 +02:00 committed by GitHub
parent d5a2c75963
commit aa27baacf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 8 deletions

View File

@ -349,6 +349,23 @@ type
desc: "The number of seconds to keep recently accessed states in memory"
name: "rest-statecache-ttl" }: Natural
restRequestTimeout* {.
defaultValue: 0
defaultValueDesc: "infinite"
desc: "The number of seconds to wait until complete REST request " &
"will be received"
name: "rest-request-timeout" }: Natural
restMaxRequestBodySize* {.
defaultValue: 16_384
desc: "Maximum size of REST request body (kilobytes)"
name: "rest-max-body-size" }: Natural
restMaxRequestHeadersSize* {.
defaultValue: 64
desc: "Maximum size of REST request headers (kilobytes)"
name: "rest-max-headers-size" }: Natural
keymanagerEnabled* {.
desc: "Enable the REST keymanager API (BETA version)"
defaultValue: false

View File

@ -61,16 +61,19 @@ type
template init(T: type RpcHttpServer, ip: ValidIpAddress, port: Port): T =
newRpcHttpServer([initTAddress(ip, port)])
template init(T: type RestServerRef, ip: ValidIpAddress, port: Port): T =
template init(T: type RestServerRef, ip: ValidIpAddress, port: Port,
config: BeaconNodeConf): T =
let address = initTAddress(ip, port)
let serverFlags = {HttpServerFlags.QueryCommaSeparatedArray,
HttpServerFlags.NotifyDisconnect}
# We increase default timeout to help validator clients who poll our server
# at least once per slot (12.seconds).
let
headersTimeout = seconds(2'i64 * int64(SECONDS_PER_SLOT))
maxHeadersSize = 65536 # 64 kilobytes
maxRequestBodySize = 16_777_216 # 16 megabytes
headersTimeout =
if config.restRequestTimeout == 0:
chronos.InfiniteDuration
else:
seconds(int64(config.restRequestTimeout))
maxHeadersSize = config.restMaxRequestHeadersSize * 1024
maxRequestBodySize = config.restMaxRequestBodySize * 1024
let res = RestServerRef.new(getRouter(), address, serverFlags = serverFlags,
httpHeadersTimeout = headersTimeout,
maxHeadersSize = maxHeadersSize,
@ -388,7 +391,7 @@ proc init*(T: type BeaconNode,
nil
let restServer = if config.restEnabled:
RestServerRef.init(config.restAddress, config.restPort)
RestServerRef.init(config.restAddress, config.restPort, config)
else:
nil
@ -418,7 +421,8 @@ proc init*(T: type BeaconNode,
config.restPort == config.keymanagerPort:
restServer
else:
RestServerRef.init(config.keymanagerAddress, config.keymanagerPort)
RestServerRef.init(config.keymanagerAddress, config.keymanagerPort,
config)
else:
nil