Skip to content

Commit

Permalink
Rewrote the check for closed connections. The crucial part is now gua…
Browse files Browse the repository at this point in the history
…rded but the lock is only acquired when connection list needs to be modified. This avoids unnecessary locking.
  • Loading branch information
mgrrx authored and jspricke committed Jan 18, 2017
1 parent 72ea719 commit fd679e5
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions clients/rospy/src/rospy/topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,19 +459,15 @@ def cleanup_cb_wrapper(s):
return True

def check(self):
new_connections = self.connections[:]
removed_connection = False

for fd in self.connection_poll.error_iter():
to_remove = [x for x in new_connections if x.fileno() == fd]

for x in to_remove:
removed_connection = True
rospydebug("removing connection to %s, connection error detected"%(x.endpoint_id))
self._remove_connection(new_connections, x)

if removed_connection:
self.connections = new_connections
fds_to_remove = list(self.connection_poll.error_iter())
if fds_to_remove:
with self.c_lock:
new_connections = self.connections[:]
to_remove = [x for x in new_connections if x.fileno() in fds_to_remove]
for x in to_remove:
rospydebug("removing connection to %s, connection error detected"%(x.endpoint_id))
self._remove_connection(new_connections, x)
self.connections = new_connections

def remove_connection(self, c):
"""
Expand Down

0 comments on commit fd679e5

Please sign in to comment.