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

Fix deadlock with LivelinessManager [11925] #2037

Merged
merged 2 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 14 additions & 8 deletions src/cpp/rtps/reader/StatefulReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,14 @@ bool StatefulReader::processDataMsg(

assert(change);

std::lock_guard<RecursiveTimedMutex> lock(mp_mutex);
std::unique_lock<RecursiveTimedMutex> lock(mp_mutex);
if (!is_alive_)
{
return false;
}

if (acceptMsgFrom(change->writerGUID, &pWP))
{
assert_writer_liveliness(change->writerGUID);

// Check if CacheChange was received or is framework data
if (!pWP || !pWP->change_was_received(change->sequenceNumber))
{
Expand Down Expand Up @@ -490,6 +488,10 @@ bool StatefulReader::processDataMsg(
return false;
}
}

lock.unlock(); // Avoid deadlock with LivelinessManager.
assert_writer_liveliness(change->writerGUID);

return true;
}

Expand All @@ -515,8 +517,6 @@ bool StatefulReader::processDataFragMsg(
// TODO: see if we need manage framework fragmented DATA message
if (acceptMsgFrom(incomingChange->writerGUID, &pWP) && pWP)
{
assert_writer_liveliness(incomingChange->writerGUID);

// Check if CacheChange was received.
if (!pWP->change_was_received(incomingChange->sequenceNumber))
{
Expand Down Expand Up @@ -575,6 +575,10 @@ bool StatefulReader::processDataFragMsg(
NotifyChanges(pWP);
}
}

lock.unlock(); // Avoid deadlock with LivelinessManager;
assert_writer_liveliness(incomingChange->writerGUID);

}

return true;
Expand Down Expand Up @@ -604,6 +608,9 @@ bool StatefulReader::processHeartbeatMsg(
{
mp_history->remove_fragmented_changes_until(firstSN, writerGUID);

// Maybe now we have to notify user from new CacheChanges.
NotifyChanges(writer);

// Try to assert liveliness if requested by proxy's logic
if (assert_liveliness)
{
Expand All @@ -615,6 +622,7 @@ bool StatefulReader::processHeartbeatMsg(
auto wlp = this->mp_RTPSParticipant->wlp();
if ( wlp != nullptr)
{
lock.unlock(); // Avoid deadlock with LivelinessManager.
wlp->sub_liveliness_manager_->assert_liveliness(
writerGUID,
liveliness_kind_,
Expand All @@ -627,10 +635,8 @@ bool StatefulReader::processHeartbeatMsg(
}
}
}

// Maybe now we have to notify user from new CacheChanges.
NotifyChanges(writer);
}

return true;
}

Expand Down
10 changes: 7 additions & 3 deletions src/cpp/rtps/reader/StatelessReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,6 @@ bool StatelessReader::processDataMsg(
{
logInfo(RTPS_MSG_IN, IDSTRING "Trying to add change " << change->sequenceNumber << " TO reader: " << m_guid);

assert_writer_liveliness(change->writerGUID);

// Ask the pool for a cache change
CacheChange_t* change_to_add = nullptr;
if (!change_pool_->reserve_cache(change_to_add))
Expand Down Expand Up @@ -456,6 +454,9 @@ bool StatelessReader::processDataMsg(
change_pool_->release_cache(change_to_add);
return false;
}

lock.unlock(); // Avoid deadlock with LivelinessManager.
assert_writer_liveliness(change->writerGUID);
}

return true;
Expand All @@ -478,7 +479,6 @@ bool StatelessReader::processDataFragMsg(
{
// Datasharing communication will never send fragments
assert(!writer.is_datasharing);
assert_writer_liveliness(writer_guid);

// Check if CacheChange was received.
if (!thereIsUpperRecordOf(writer_guid, incomingChange->sequenceNumber))
Expand Down Expand Up @@ -564,6 +564,10 @@ bool StatelessReader::processDataFragMsg(
}
}
}

lock.unlock(); // Avoid deadlock with LivelinessManager.
assert_writer_liveliness(writer_guid);

return true;
}
}
Expand Down