Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP: Warning and test fix #943

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/http_plugin/http_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ namespace eosio {
// returns true if `category` is enabled in http_plugin
bool http_plugin::is_enabled(api_category category) const {
return std::any_of(my->categories_by_address.begin(), my->categories_by_address.end(),
[&category, this](const auto& entry) {
[&category](const auto& entry) {
const auto& [address, categories] = entry;
return categories.contains(category);
});
Expand Down
12 changes: 10 additions & 2 deletions plugins/http_plugin/tests/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ BOOST_FIXTURE_TEST_CASE(bytes_in_flight, http_plugin_test_fixture) {
req.set(http::field::host, "127.0.0.1:8891");
boost::beast::http::write(s, req);
}
//make sure got to the point http threads had responses queued
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does it matter if the response is queued or not at this point?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This avoids boost::beast::http::status::service_unavailable on my machine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe after the boost::beast::http::write(s, req) try doing a s.wait(wait_read), that will guarantee that the response is in flight. just a guess though

std::this_thread::sleep_for(std::chrono::seconds(5));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why here sleeping 5 seconds but below sleeping 1 second?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the 1s is not for 4mb messages.

};

auto drain_http_replies = [&](unsigned max = std::numeric_limits<unsigned>::max()) {
Expand Down Expand Up @@ -642,13 +644,14 @@ BOOST_FIXTURE_TEST_CASE(bytes_in_flight, http_plugin_test_fixture) {

//load up some more requests that exceed max
send_4mb_requests(32u);
//make sure got to the point http threads had responses queued
std::this_thread::sleep_for(std::chrono::seconds(1));
//now rip these connections out before the responses are completely sent
connections.clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood your description right, this is the area that is problematic. Between this line and the line below the http plugin needs to have cleaned up all its ownstanding async_writes. Just closing the socket here does indeed send the FIN but the http threads need time to wake up and handle that error on the async_write to then clear out what's in flight.

I wonder if what might work is to shutdown each connection and then async_read on each one until getting confirmation the remote side disconnected via an error code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would likely work. I added a check for bytes_in_flight since that is really what we want to test anyway. We want to verify that bytes in flight goes to 0 once connections are closed.

//send some requests that should work still
send_4mb_requests(8u);
r = drain_http_replies();
for (const auto& e : r) {
ilog( "response: ${r}, count: ${c}", ("r", std::string(obsolete_reason(e.first)))("c", e.second));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I almost thought the r in ${r} was the r in r = drain_http_replies().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

}
BOOST_REQUIRE_EQUAL(r[boost::beast::http::status::ok], 8u);
}

Expand Down Expand Up @@ -677,6 +680,8 @@ BOOST_FIXTURE_TEST_CASE(requests_in_flight, http_plugin_test_fixture) {
req.set(http::field::host, "127.0.0.1:8892");
boost::beast::http::write(s, req);
}
//make sure got to the point http threads had responses queued
std::this_thread::sleep_for(std::chrono::seconds(1));
};

auto scan_http_replies = [&]() {
Expand Down Expand Up @@ -712,6 +717,9 @@ BOOST_FIXTURE_TEST_CASE(requests_in_flight, http_plugin_test_fixture) {
//requests should still work
send_requests(8u);
r = scan_http_replies();
for (const auto& e : r) {
ilog( "response: ${r}, count: ${c}", ("r", std::string(obsolete_reason(e.first)))("c", e.second));
}
BOOST_REQUIRE_EQUAL(r[boost::beast::http::status::ok], 8u);
connections.clear();
}
Expand Down