Skip to content

Commit 3d9972e

Browse files
joaofesilvaduartenfonseca
authored andcommitted
check routing ready on options_condition predicate
Summary Fix liveloop introduced by 64aa478 Details Fix a case where if vsomeip adds multicast options to join to the options_queue_ but is_external_routing_ready() is evaluated to false it would get stuck in a liveloop. This was introduced in 64aa478 by adding a check for !options_queue_.empty() in the options_condition_ predicate By including the check to is_external_routing_ready() on the options_condition_ predicate the issue no longer occurs
1 parent 52e3630 commit 3d9972e

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

implementation/endpoints/include/endpoint_manager_impl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class endpoint_manager_impl : public endpoint_manager_base {
128128

129129
// process join/leave options
130130
void process_multicast_options();
131+
bool check_options_queue();
131132

132133
bool is_used_endpoint(endpoint* const _endpoint) const;
133134

implementation/endpoints/src/endpoint_manager_impl.cpp

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,48 +1348,56 @@ endpoint_manager_impl::add_multicast_option(const multicast_option_t &_option) {
13481348
options_condition_.notify_one();
13491349
}
13501350

1351+
bool endpoint_manager_impl::check_options_queue() {
1352+
1353+
if (options_queue_.empty()) {
1354+
return false;
1355+
}
1356+
1357+
if (!static_cast<routing_manager_impl*>(rm_)->is_external_routing_ready()) {
1358+
return false;
1359+
}
1360+
1361+
return true;
1362+
}
1363+
13511364
void
13521365
endpoint_manager_impl::process_multicast_options() {
13531366

13541367
std::unique_lock<std::mutex> its_lock(options_mutex_);
13551368
while (is_processing_options_) {
13561369
options_condition_.wait(
1357-
its_lock, [this] { return !options_queue_.empty() || !is_processing_options_; });
1370+
its_lock, [this] { return check_options_queue() || !is_processing_options_; });
13581371

13591372
if (!is_processing_options_) {
13601373
return;
13611374
}
13621375

1363-
if (options_queue_.size() > 0
1364-
&& static_cast<routing_manager_impl*>(rm_)->is_external_routing_ready()) {
1365-
auto its_front = options_queue_.front();
1366-
options_queue_.pop();
1367-
auto its_udp_server_endpoint =
1368-
std::dynamic_pointer_cast<udp_server_endpoint_impl>(its_front.endpoint_);
1369-
if (its_udp_server_endpoint) {
1370-
// Unlock before setting the option as this might block
1371-
its_lock.unlock();
1372-
1373-
boost::system::error_code its_error;
1374-
its_udp_server_endpoint->set_multicast_option(
1375-
its_front.address_, its_front.is_join_, its_error);
1376+
auto its_front = options_queue_.front();
1377+
options_queue_.pop();
1378+
auto its_udp_server_endpoint =
1379+
std::dynamic_pointer_cast<udp_server_endpoint_impl>(its_front.endpoint_);
1380+
if (its_udp_server_endpoint) {
1381+
// Unlock before setting the option as this might block
1382+
its_lock.unlock();
13761383

1384+
boost::system::error_code its_error;
1385+
its_udp_server_endpoint->set_multicast_option(its_front.address_, its_front.is_join_,
1386+
its_error);
13771387

1378-
// Lock again after setting the option
1379-
its_lock.lock();
1388+
// Lock again after setting the option
1389+
its_lock.lock();
13801390

1381-
if (its_error) {
1382-
VSOMEIP_ERROR << __func__ << ": "
1383-
<< (its_front.is_join_ ? "joining " : "leaving ")
1384-
<< its_front.address_ << " (" << its_error.message() << ")";
1391+
if (its_error) {
1392+
VSOMEIP_ERROR << __func__ << ": " << (its_front.is_join_ ? "joining " : "leaving ")
1393+
<< its_front.address_ << " (" << its_error.message() << ")";
13851394

1386-
if(its_front.is_join_) {
1387-
multicast_option_t its_leave_option {
1388-
its_front.endpoint_, false, its_front.address_};
1395+
if(its_front.is_join_) {
1396+
multicast_option_t its_leave_option {its_front.endpoint_, false,
1397+
its_front.address_};
13891398

1390-
options_queue_.push(its_leave_option);
1391-
options_queue_.push(its_front);
1392-
}
1399+
options_queue_.push(its_leave_option);
1400+
options_queue_.push(its_front);
13931401
}
13941402
}
13951403
}

0 commit comments

Comments
 (0)