diff --git a/lbry/torrent/tracker.py b/lbry/torrent/tracker.py index cc263b380..c46f63bbc 100644 --- a/lbry/torrent/tracker.py +++ b/lbry/torrent/tracker.py @@ -120,11 +120,7 @@ async def get_peer_list(info_hash, node_id, port, tracker_ip, tracker_port, stop transport, _ = await asyncio.get_running_loop().create_datagram_endpoint(lambda: proto, local_addr=("0.0.0.0", 0)) try: reply, _ = await proto.announce(info_hash, node_id, port, tracker_ip, tracker_port, stopped=stopped) - return reply.peers - except asyncio.CancelledError: - raise - except Exception as exc: - log.warning("Error fetching from tracker: %s", exc.args) - return [] + return reply finally: - transport.close() \ No newline at end of file + if not transport.is_closing(): + transport.close() diff --git a/tests/unit/torrent/test_tracker.py b/tests/unit/torrent/test_tracker.py index 3c4c0fa9d..a03493118 100644 --- a/tests/unit/torrent/test_tracker.py +++ b/tests/unit/torrent/test_tracker.py @@ -60,10 +60,10 @@ class UDPTrackerClientTestCase(AsyncioTestCase): async def test_announce_using_helper_function(self): info_hash = random.getrandbits(160).to_bytes(20, "big", signed=False) - peers = await get_peer_list(info_hash, None, 4444, "127.0.0.1", 59900) + announcemenet = await get_peer_list(info_hash, None, 4444, "127.0.0.1", 59900) + peers = announcemenet.peers self.assertEqual(peers, [CompactIPv4Peer(int.from_bytes(bytes([127, 0, 0, 1]), "big", signed=False), 4444)]) - peers = await get_peer_list(info_hash, None, 4444, "127.0.0.1", 59900, stopped=True) - self.assertEqual(peers, []) + self.assertEqual((await get_peer_list(info_hash, None, 4444, "127.0.0.1", 59900, stopped=True)).peers, []) async def test_error(self): info_hash = random.getrandbits(160).to_bytes(20, "big", signed=False)