Skip to content

Commit 6a22d85

Browse files
authored
Crash problem is fixed when an adress could not be translated by address provider. (#1073) (#1074)
1 parent d9f4357 commit 6a22d85

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

hazelcast/src/hazelcast/client/network.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,24 @@ ClientConnectionManagerImpl::translate(const member& m)
917917
return m.get_address();
918918
}
919919

920-
return *address_provider_->translate(m.get_address());
920+
try {
921+
boost::optional<address> addr =
922+
address_provider_->translate(m.get_address());
923+
924+
if (!addr) {
925+
throw exception::hazelcast_(boost::str(
926+
boost::format("Address Provider could not translate %1%") % m));
927+
}
928+
929+
return *addr;
930+
} catch (const exception::hazelcast_&) {
931+
logger_.log(
932+
logger::level::warning,
933+
boost::str(boost::format("Address Provider could not translate %1%") %
934+
m));
935+
936+
throw;
937+
}
921938
}
922939

923940
std::shared_ptr<connection::Connection>

hazelcast/test/src/HazelcastTests8.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <hazelcast/client/connection/ClientConnectionManagerImpl.h>
3838
#include <hazelcast/client/connection/Connection.h>
3939
#include <hazelcast/client/connection/AddressProvider.h>
40+
#include <hazelcast/client/spi/impl/discovery/remote_address_provider.h>
4041
#include <hazelcast/client/entry_event.h>
4142
#include <hazelcast/client/exception/protocol_exceptions.h>
4243
#include <hazelcast/client/hazelcast_client.h>
@@ -2316,6 +2317,29 @@ TEST_F(connection_manager_translate, default_config_uses_private_addresses)
23162317
{
23172318
ASSERT_FALSE(client_config().get_network_config().use_public_address());
23182319
}
2320+
2321+
TEST_F(
2322+
connection_manager_translate,
2323+
if_remote_adress_provider_cannot_translate_adress_translate_should_throw_an_exception)
2324+
{
2325+
auto client = new_client().get();
2326+
spi::ClientContext ctx(client);
2327+
connection::ClientConnectionManagerImpl connection_manager(
2328+
ctx,
2329+
std::unique_ptr<connection::AddressProvider>(
2330+
new spi::impl::discovery::remote_address_provider{
2331+
[]() { return std::unordered_map<address, address>{}; }, true }));
2332+
2333+
std::random_device rand{};
2334+
member dummy_member(
2335+
address{ "255.255.255.255", 40000 },
2336+
boost::uuids::basic_random_generator<std::random_device>{ rand }(),
2337+
false,
2338+
std::unordered_map<std::string, std::string>{},
2339+
std::unordered_map<endpoint_qualifier, address>{});
2340+
EXPECT_THROW(connection_manager.get_or_connect(dummy_member),
2341+
exception::hazelcast_);
2342+
}
23192343
} // namespace test
23202344
} // namespace client
23212345
} // namespace hazelcast

0 commit comments

Comments
 (0)