Fix potential deadlock

- alreadyAttemptedConnectionsListLock probably deadlocked
- removed locking where unnecessary and rewrote the important part with
  proper locking
This commit is contained in:
Peter Šurda 2017-02-28 00:12:49 +01:00
parent af8957ed72
commit d0b0d15dc3
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -85,9 +85,7 @@ class outgoingSynSender(threading.Thread, StoppableThread):
break break
random.seed() random.seed()
peer = self._getPeer() peer = self._getPeer()
shared.alreadyAttemptedConnectionsListLock.acquire()
while peer in shared.alreadyAttemptedConnectionsList or peer.host in shared.connectedHostsList: while peer in shared.alreadyAttemptedConnectionsList or peer.host in shared.connectedHostsList:
shared.alreadyAttemptedConnectionsListLock.release()
# print 'choosing new sample' # print 'choosing new sample'
random.seed() random.seed()
peer = self._getPeer() peer = self._getPeer()
@ -97,16 +95,12 @@ class outgoingSynSender(threading.Thread, StoppableThread):
# Clear out the shared.alreadyAttemptedConnectionsList every half # Clear out the shared.alreadyAttemptedConnectionsList every half
# hour so that this program will again attempt a connection # hour so that this program will again attempt a connection
# to any nodes, even ones it has already tried. # to any nodes, even ones it has already tried.
with shared.alreadyAttemptedConnectionsListLock:
if (time.time() - shared.alreadyAttemptedConnectionsListResetTime) > 1800: if (time.time() - shared.alreadyAttemptedConnectionsListResetTime) > 1800:
shared.alreadyAttemptedConnectionsList.clear() shared.alreadyAttemptedConnectionsList.clear()
shared.alreadyAttemptedConnectionsListResetTime = int( shared.alreadyAttemptedConnectionsListResetTime = int(
time.time()) time.time())
shared.alreadyAttemptedConnectionsListLock.acquire()
shared.alreadyAttemptedConnectionsList[peer] = 0 shared.alreadyAttemptedConnectionsList[peer] = 0
try:
shared.alreadyAttemptedConnectionsListLock.release()
except threading.ThreadError as e:
pass
if self._stopped: if self._stopped:
break break
self.name = "outgoingSynSender-" + peer.host.replace(":", ".") # log parser field separator self.name = "outgoingSynSender-" + peer.host.replace(":", ".") # log parser field separator