Skip to content

Commit

Permalink
Merge pull request #3653 from devos50/various_fixes
Browse files Browse the repository at this point in the history
Various fixes for Tribler 7.1
  • Loading branch information
xoriole authored May 30, 2018
2 parents 4135563 + 190d028 commit 79c646b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Tribler/Core/Modules/restapi/torrentinfo_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from libtorrent import bdecode, bencode
from twisted.internet.defer import Deferred
from twisted.internet.error import DNSLookupError, ConnectError
from twisted.internet.error import DNSLookupError, ConnectError, ConnectionLost
from twisted.web import http, resource
from twisted.web.server import NOT_DONE_YET

Expand Down Expand Up @@ -85,7 +85,7 @@ def on_metainfo_timeout(_):
self.finish_request(request)

def on_lookup_error(failure):
failure.trap(ConnectError, DNSLookupError, HttpError)
failure.trap(ConnectError, DNSLookupError, HttpError, ConnectionLost)
request.setResponseCode(http.INTERNAL_SERVER_ERROR)
request.write(json.dumps({"error": failure.getErrorMessage()}))
self.finish_request(request)
Expand Down
12 changes: 10 additions & 2 deletions Tribler/Core/TorrentChecker/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def __init__(self, tracker_url, tracker_address, announce_page, timeout, connect
self._content_length = None
self._received_length = None
self.result_deferred = None
self._parse_deferred = None
self.request = None
self._connection_pool = connection_pool if connection_pool else HTTPConnectionPool(reactor, False)

Expand Down Expand Up @@ -266,7 +267,8 @@ def on_response(self, response):
return

# All ok, parse the body
self.register_task("parse_body", readBody(response).addCallbacks(self._process_scrape_response, self.on_error))
self._parse_deferred = readBody(response).addCallbacks(self._process_scrape_response, self.on_error)
self.register_task("parse_body", self._parse_deferred)

def _on_cancel(self, _):
"""
Expand Down Expand Up @@ -346,8 +348,14 @@ def cleanup(self):
"""
yield self._connection_pool.closeCachedConnections()
yield super(HttpTrackerSession, self).cleanup()
self.request = None

# If we are in the process of reading a HTTP response from a remote server (with the readBody) method, it might
# be that it is called after the deferred has been cancelled already (by the super.cleanup method). This would
# result in an AlreadyCalled error. The following line prevents this behaviour.
if self._parse_deferred:
self._parse_deferred._suppressAlreadyCalled = True

self.request = None
self.result_deferred = None


Expand Down
4 changes: 2 additions & 2 deletions Tribler/Core/TorrentChecker/torrent_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from twisted.internet import reactor
from twisted.internet.defer import DeferredList, CancelledError, fail, succeed, maybeDeferred
from twisted.internet.error import ConnectingCancelledError
from twisted.internet.error import ConnectingCancelledError, ConnectionLost
from twisted.python.failure import Failure
from twisted.web.client import HTTPConnectionPool

Expand Down Expand Up @@ -254,7 +254,7 @@ def on_session_error(self, session, failure):
And trap CancelledErrors that can be thrown when shutting down.
:param failure: The failure object raised by Twisted.
"""
failure.trap(ValueError, CancelledError, ConnectingCancelledError, RuntimeError)
failure.trap(ValueError, CancelledError, ConnectingCancelledError, ConnectionLost, RuntimeError)
self._logger.warning(u"Got session error for URL %s: %s", session.tracker_url, failure)

self.clean_session(session)
Expand Down
3 changes: 3 additions & 0 deletions TriblerGUI/tribler_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,9 @@ def show_force_shutdown():
self.downloads_page.stop_loading_downloads()
request_queue.clear()

# Stop the token balance timer
self.token_refresh_timer.stop()

def closeEvent(self, close_event):
self.close_tribler()
close_event.ignore()
Expand Down
10 changes: 6 additions & 4 deletions TriblerGUI/widgets/leftmenuplaylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,24 @@ def load_list(self, infohash):
self.set_loading()

if self.files_request_timer:
self.files_request_timer.invalidate()
self.files_request_timer.stop()

self.files_request_timer = QTimer()
self.files_request_timer.timeout.connect(self.perform_get_files_request)
self.files_request_timer.start(1000)

def perform_get_files_request(self):
self.files_request_mgr = TriblerRequestManager()
self.files_request_mgr.perform_request("downloads/%s/files" % self.infohash, self.on_received_files)
self.files_request_mgr.perform_request("downloads/%s/files" % self.infohash, self.on_received_files,
capture_errors=False)

def on_received_files(self, files):
if "files" not in files or not files["files"]:
return

self.files_request_timer.stop()
self.files_request_timer = None
if self.files_request_timer:
self.files_request_timer.stop()
self.files_request_timer = None

self.set_files(files["files"])
self.loaded_list = True
Expand Down

0 comments on commit 79c646b

Please sign in to comment.