From 9766a7a3f9e9f3d32fdefeecc65ecd99cb7a42b7 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Sat, 27 Aug 2022 13:02:30 -0400 Subject: [PATCH] fix a number of issues with http-max-bytes-in-flight-mb configuration allow http-max-bytes-in-flight-mb bigger than 4GB; make -1 indicate unlimited; validate value of http-max-bytes-in-flight-mb; correct http-max-bytes-in-flight-mb description (changing 503 error response when exceeded to 429 error response when exceeded --- plugins/http_plugin/http_plugin.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/http_plugin/http_plugin.cpp b/plugins/http_plugin/http_plugin.cpp index 2d6946d464..acd10b9a02 100644 --- a/plugins/http_plugin/http_plugin.cpp +++ b/plugins/http_plugin/http_plugin.cpp @@ -697,8 +697,8 @@ class http_plugin_impl : public std::enable_shared_from_this { "Specify if Access-Control-Allow-Credentials: true should be returned on each request.") ("max-body-size", bpo::value()->default_value(my->max_body_size), "The maximum body size in bytes allowed for incoming RPC requests") - ("http-max-bytes-in-flight-mb", bpo::value()->default_value(500), - "Maximum size in megabytes http_plugin should use for processing http requests. 503 error response when exceeded." ) + ("http-max-bytes-in-flight-mb", bpo::value()->default_value(500), + "Maximum size in megabytes http_plugin should use for processing http requests. -1 for unlimited. 429 error response when exceeded." ) ("http-max-response-time-ms", bpo::value()->default_value(30), "Maximum time for processing a request.") ("verbose-http-errors", bpo::bool_switch()->default_value(false), @@ -721,7 +721,14 @@ class http_plugin_impl : public std::enable_shared_from_this { EOS_ASSERT( my->thread_pool_size > 0, chain::plugin_config_exception, "http-threads ${num} must be greater than 0", ("num", my->thread_pool_size)); - my->max_bytes_in_flight = options.at( "http-max-bytes-in-flight-mb" ).as() * 1024 * 1024; + auto max_bytes_mb = options.at( "http-max-bytes-in-flight-mb" ).as(); + EOS_ASSERT( (max_bytes_mb >= -1 && max_bytes_mb < std::numeric_limits::max() / (1024 * 1024)), chain::plugin_config_exception, + "http-max-bytes-in-flight-mb (${max_bytes_mb}) must be equal to or greater than -1 and less than ${max}", ("max_bytes_mb", max_bytes_mb) ("max", std::numeric_limits::max() / (1024 * 1024)) ); + if ( max_bytes_mb == -1 ) { + my->max_bytes_in_flight = std::numeric_limits::max(); + } else { + my->max_bytes_in_flight = max_bytes_mb * 1024 * 1024; + } my->max_response_time = fc::microseconds( options.at("http-max-response-time-ms").as() * 1000 ); my->validate_host = options.at("http-validate-host").as();