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

remove deadlock danger when removing Connections from a ConnectionMap #1952

Closed

Conversation

fronneburg
Copy link
Contributor

Fixes #1951

This PR is [ready] for review.

Risk

This PR makes [no] API changes.

Summary

Created a new "RemoveConnection" method which safely removes a Connection object from the ConnectionMap. Before calling "erase" on the connection object, the object's ref-count is incremented by assigning it to a local "ConnectionSPtr" variable. We then call "erase", NOT triggering the destructor, then release the "connections_lock_", and then let the local variable go out of scope, thus delaying the destructor until after the lock was released.

CLA

@@ -756,25 +748,53 @@ void TransportAdapterImpl::RemoveFinalizedConnection(
const DeviceUID& device_handle, const ApplicationHandle& app_handle) {
const DeviceUID device_uid = device_handle;
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoWriteLock lock(connections_lock_);
connections_lock_.AcquireForWriting();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fronneburg why did you remove AutoLock in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LuxoftAKutsan we need to make sure that the lock is released first, and THEN let "connection" go out of scope.

void TransportAdapterImpl::RemoveConnection(
const DeviceUID& device_id, const ApplicationHandle& app_handle) {
ConnectionSPtr connection;
connections_lock_.AcquireForWriting();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fronneburg I would prefer using RAII here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same response here.

@JenkinsSDLOnCloud
Copy link

Can one of the admins verify this patch?

@Jack-Byrne
Copy link
Collaborator

@fronneburg Why is it important that the calling the connection destructor is delayed until after the lock is released?

@fronneburg
Copy link
Contributor Author

@JackLivio, we found a deadlock when the connection destructor (actually the "ThreadedConnection" Xevo implementation) tried to "join" a thread that was waiting on the "connections_lock_" in TransportAdapterImpl::ConnectionFinished.

@iCollin iCollin mentioned this pull request May 18, 2020
1 task
@iCollin
Copy link
Collaborator

iCollin commented May 18, 2020

Closed in favor of #3371 which is based on latest develop and changes the log type from TRACE to DEBUG.

@iCollin iCollin closed this May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants