Skip to content

Commit 848ed89

Browse files
authored
fix(network): fix heartbeat failure caused by inability to obtain peer address when receiving UDP data (#2364)
Fix #2363. The root cause is that when starting onebox with `--use_product_config`, both replica servers and meta servers use [src/server/config.ini](https://github.com/apache/incubator-pegasus/blob/a9a11da886bd32d170fc166c08b69210d89d6a52/src/server/config.ini) instead of [src/server/config.min.ini](https://github.com/apache/incubator-pegasus/blob/a9a11da886bd32d170fc166c08b69210d89d6a52/src/server/config.min.ini). As a result, beacons are sent and received over **UDP** instead of **TCP**. The UDP implementation uses Boost.Asio APIs. If the sender socket does not call `connect()`, then calling `remote_endpoint()` on the receiver socket will always fail. The fix is to remove the logic that calls `remote_endpoint()` on the receiving side. This logic was introduced in #1658 to handle cross-network scenarios (when the address in the message header differs from the actual socket connection address, the non-forwarding path corrects it to a recognizable address). Since UDP is primarily used for the heartbeat scenario, and `beacon_msg` already contains `from_node` and `hp_from_node`, this logic can be removed.
1 parent 817a18d commit 848ed89

File tree

1 file changed

+0
-30
lines changed

1 file changed

+0
-30
lines changed

src/rpc/asio_net_provider.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -348,19 +348,6 @@ void asio_udp_provider::do_receive()
348348
return;
349349
}
350350

351-
// Get the remote endpoint of the socket.
352-
boost::system::error_code ec;
353-
auto remote = _socket->remote_endpoint(ec);
354-
if (ec) {
355-
LOG_ERROR("failed to get the remote endpoint: {}", ec.message());
356-
do_receive();
357-
return;
358-
}
359-
360-
auto ip = remote.address().to_v4().to_ulong();
361-
auto port = remote.port();
362-
const auto &remote_addr = ::dsn::rpc_address(ip, port);
363-
364351
auto hdr_format = message_parser::get_header_type(_recv_reader._buffer.data());
365352
if (NET_HDR_INVALID == hdr_format) {
366353
LOG_ERROR("{}: asio udp read failed: invalid header type '{}'",
@@ -384,23 +371,6 @@ void asio_udp_provider::do_receive()
384371
return;
385372
}
386373

387-
if (msg->header->from_address != remote_addr) {
388-
if (!msg->header->context.u.is_forwarded) {
389-
msg->header->from_address = remote_addr;
390-
LOG_DEBUG("{}: message's from_address {} is not equal to socket's remote_addr "
391-
"{}, assign it to remote_addr.",
392-
_address,
393-
msg->header->from_address,
394-
remote_addr);
395-
} else {
396-
LOG_DEBUG("{}: message's from_address {} is not equal to socket's remote_addr "
397-
"{}, but it's forwarded message, ignore it!.",
398-
_address,
399-
msg->header->from_address,
400-
remote_addr);
401-
}
402-
}
403-
404374
msg->to_address = _address;
405375
msg->to_host_port = _hp;
406376
if (msg->header->context.u.is_request) {

0 commit comments

Comments
 (0)