Skip to content

Commit e21f9cf

Browse files
xoriolekozlovsky
authored andcommitted
Cherry-pick Reset the tracker peers count if tracker error alert is received
(cherry picked from commit 716112e)
1 parent 80cf3d7 commit e21f9cf

File tree

1 file changed

+5
-1
lines changed
  • src/tribler/core/components/libtorrent/download_manager

1 file changed

+5
-1
lines changed

src/tribler/core/components/libtorrent/download_manager/download.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,16 @@ def on_tracker_reply_alert(self, alert: lt.tracker_reply_alert):
312312
self.tracker_status[alert.url] = [alert.num_peers, 'Working']
313313

314314
def on_tracker_error_alert(self, alert: lt.tracker_error_alert):
315+
"""
316+
This alert is generated on tracker timeouts, premature disconnects, invalid response
317+
or an HTTP response other than "200 OK". - From Libtorrent documentation.
318+
"""
315319
# The try-except block is added as a workaround to suppress UnicodeDecodeError in `repr(alert)`,
316320
# `alert.url` and `alert.msg`. See https://github.com/arvidn/libtorrent/issues/143
317321
try:
318322
self._logger.error(f'On tracker error alert: {alert}')
319323
url = alert.url
320324

321-
peers = self.tracker_status[url][0] if url in self.tracker_status else 0
322325
if alert.msg:
323326
status = 'Error: ' + alert.msg
324327
elif alert.status_code > 0:
@@ -328,6 +331,7 @@ def on_tracker_error_alert(self, alert: lt.tracker_error_alert):
328331
else:
329332
status = 'Not working'
330333

334+
peers = 0 # If there is a tracker error, alert.num_peers is not available. So resetting peer count to zero.
331335
self.tracker_status[url] = [peers, status]
332336
except UnicodeDecodeError as e:
333337
self._logger.warning(f'UnicodeDecodeError in on_tracker_error_alert: {e}')

0 commit comments

Comments
 (0)