Skip to content

Commit a3765cc

Browse files
douglas-raillard-armmarcbonnici
authored andcommitted
target: Remove duplicated disconnection logic
The logic in Target.disconnect() appears to have been duplicated by error. While _probably_ harmless, this is at least confusing, and since this happens outside of the lock, this may actually be a real problem.
1 parent 20e5bcd commit a3765cc

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

devlib/target.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -548,28 +548,23 @@ async def check(**kwargs):
548548
await check(as_root=True)
549549

550550
def disconnect(self):
551-
connections = self._conn.get_all_values()
552-
# Now that we have all the connection objects, we simply reset the TLS
553-
# property so that the connections we got will not be reused anywhere.
554-
del self._conn
555-
556-
unused_conns = self._unused_conns
557-
self._unused_conns.clear()
558-
559-
for conn in itertools.chain(connections, self._unused_conns):
560-
conn.close()
551+
with self._lock:
552+
thread_conns = self._conn.get_all_values()
553+
# Now that we have all the connection objects, we simply reset the
554+
# TLS property so that the connections we obtained will not be
555+
# reused anywhere.
556+
del self._conn
561557

562-
pool = self._async_pool
563-
self._async_pool = None
564-
if pool is not None:
565-
pool.__exit__(None, None, None)
558+
unused_conns = list(self._unused_conns)
559+
self._unused_conns.clear()
566560

567-
with self._lock:
568-
connections = self._conn.get_all_values()
569-
for conn in itertools.chain(connections, self._unused_conns):
561+
for conn in itertools.chain(thread_conns, unused_conns):
570562
conn.close()
571-
if self._async_pool is not None:
572-
self._async_pool.__exit__(None, None, None)
563+
564+
pool = self._async_pool
565+
self._async_pool = None
566+
if pool is not None:
567+
pool.__exit__(None, None, None)
573568

574569
def __enter__(self):
575570
return self

0 commit comments

Comments
 (0)