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

Log resource limit disconnections. #4035

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/ripple/app/main/GRPCServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ GRPCServerImpl::CallData<Request, Response>::process(
{
auto usage = getUsage();
bool isUnlimited = clientIsUnlimited();
if (!isUnlimited && usage.disconnect())
if (!isUnlimited && usage.disconnect(app_.journal("gRPCServer")))
{
grpc::Status status{
grpc::StatusCode::RESOURCE_EXHAUSTED,
"usage balance exceeds threshhold"};
"usage balance exceeds threshold"};
responder_.FinishWithError(status, this);
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/overlay/impl/OverlayImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ OverlayImpl::onHandoff(

auto consumer = m_resourceManager.newInboundEndpoint(
beast::IPAddressConversion::from_asio(remote_endpoint));
if (consumer.disconnect())
if (consumer.disconnect(journal))
return handoff;

auto const slot = m_peerFinder->new_inbound_slot(
Expand Down Expand Up @@ -392,7 +392,7 @@ OverlayImpl::connect(beast::IP::Endpoint const& remote_endpoint)
assert(work_);

auto usage = resourceManager().newOutboundEndpoint(remote_endpoint);
if (usage.disconnect())
if (usage.disconnect(journal_))
{
JLOG(journal_.info()) << "Over resource limit: " << remote_endpoint;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/overlay/impl/PeerImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ PeerImp::removeTxQueue(uint256 const& hash)
void
PeerImp::charge(Resource::Charge const& fee)
{
if ((usage_.charge(fee) == Resource::drop) && usage_.disconnect() &&
if ((usage_.charge(fee) == Resource::drop) && usage_.disconnect(p_journal_) &&
strand_.running_in_this_thread())
{
// Sever the connection
Expand Down
3 changes: 2 additions & 1 deletion src/ripple/resource/Consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef RIPPLE_RESOURCE_CONSUMER_H_INCLUDED
#define RIPPLE_RESOURCE_CONSUMER_H_INCLUDED

#include <ripple/basics/Log.h>
#include <ripple/resource/Charge.h>
#include <ripple/resource/Disposition.h>

Expand Down Expand Up @@ -76,7 +77,7 @@ class Consumer

/** Returns `true` if the consumer should be disconnected. */
bool
disconnect();
disconnect(beast::Journal const& j);

/** Returns the credit balance representing consumption. */
int
Expand Down
9 changes: 7 additions & 2 deletions src/ripple/resource/impl/Consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,15 @@ Consumer::warn()
}

bool
Consumer::disconnect()
Consumer::disconnect(beast::Journal const& j)
{
assert(m_entry != nullptr);
return m_logic->disconnect(*m_entry);
bool const d = m_logic->disconnect(*m_entry);
if (d)
{
JLOG(j.debug()) << "disconnecting " << entry().to_string();
Copy link
Collaborator

Choose a reason for hiding this comment

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

The rest of this function uses *m_entry, so using entry() here (which is equivalent other than asserting again) seems odd.

}
return d;
}

int
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/rpc/impl/ServerHandlerImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ ServerHandlerImp::processSession(
Json::Value const& jv)
{
auto is = std::static_pointer_cast<WSInfoSub>(session->appDefined);
if (is->getConsumer().disconnect())
if (is->getConsumer().disconnect(m_journal))
{
session->close(
{boost::beast::websocket::policy_error, "threshold exceeded"});
Expand Down Expand Up @@ -687,7 +687,7 @@ ServerHandlerImp::processRequest(
{
usage = m_resourceManager.newInboundEndpoint(
remoteIPAddress, role == Role::PROXY, forwardedFor);
if (usage.disconnect())
if (usage.disconnect(m_journal))
{
if (!batch)
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/resource/Logic_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class ResourceManager_test : public beast::unit_test::suite
if (c.charge(fee) == drop)
{
// Disconnect abusive Consumer
BEAST_EXPECT(c.disconnect() == limited);
BEAST_EXPECT(c.disconnect(j) == limited);
break;
}
++logic.clock();
Expand Down