Skip to content

Commit

Permalink
Fix duplicated error log in forwarder
Browse files Browse the repository at this point in the history
  • Loading branch information
JackyWoo committed Jan 5, 2024
1 parent 6e728cb commit 693c433
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions src/Service/ForwardConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void ForwardConnection::connect()
catch (...)
{
if (i == (num_retries - 1))
tryLogCurrentException(log, "Exception when connect to server " + endpoint);
throw Exception(ErrorCodes::ALL_CONNECTION_TRIES_FAILED, "Connect to forward server {} failed", endpoint);
else
Poco::Thread::current()->sleep(1000);
}
Expand All @@ -72,22 +72,19 @@ void ForwardConnection::disconnect()

void ForwardConnection::send(ForwardRequestPtr request)
{
if (!connected)
connect();

if (!connected)
throw Exception("Connect to server failed", ErrorCodes::ALL_CONNECTION_TRIES_FAILED);

LOG_TRACE(log, "Forward request {} to endpoint {}", request->toString(), endpoint);

if (unlikely(!connected))
connect();

try
{
request->write(*out);
}
catch (...)
{
disconnect();
throw Exception(ErrorCodes::NETWORK_ERROR, "Exception while send request to {}", endpoint);
throw;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Service/RequestForwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void RequestForwarder::runSend(RunnerId runner_id)
}
catch (...)
{
tryLogCurrentException(log, "Error when forwarding request to leader for runner " + std::to_string(runner_id));
tryLogCurrentException(log, "Error when forwarding request with runner " + std::to_string(runner_id));
request_processor->onError(
false,
nuraft::cmd_result_code::FAILED,
Expand Down

0 comments on commit 693c433

Please sign in to comment.