# Buggy code
def on_session_error(self, session, failure):
    """
    Handles the scenario of when a tracker session has failed by calling the
    tracker_manager's update_tracker_info function.
    Trap value errors that are thrown by e.g. the HTTPTrackerSession when a connection fails.
    And trap CancelledErrors that can be thrown when shutting down.
    :param failure: The failure object raised by Twisted.
    """
    failure.trap(ValueError, CancelledError, ConnectingCancelledError, RuntimeError)
    self._logger.warning(
        "Got session error for URL %s: %s", session.tracker_url, failure
    )

    # Do not update if the connection got cancelled, we are probably shutting down
    # and the tracker_manager may have shutdown already.
    if failure.check(CancelledError, ConnectingCancelledError) is None:
        self.tribler_session.lm.tracker_manager.update_tracker_info(
            session.tracker_url, False
        )

    failure.tracker_url = session.tracker_url
    return failure


# Traceback (AssertionError)
Tuples differ: (2, ('127.0.0.1', [5, 4, 3, 2,... != (2, ('127.0.0.1', [5, 4, 3, 2,...

First differing element 2:
u'None'
''

- (2, ('127.0.0.1', [5, 4, 3, 2, 1]), u'None')
?                                     - ----

+ (2, ('127.0.0.1', [5, 4, 3, 2, 1]), '')
Stacktrace

Traceback (most recent call last):
File "c:\python27\lib\unittest\case.py", line 329, in run
testMethod()
File "C:\workspace\jenkins\workspace\GH_Tribler_PR_tests_win64\tribler\Tribler\Test\test_as_server.py", line 58, in check
result = fun(*argv, **kwargs)
File "C:\workspace\jenkins\workspace\GH_Tribler_PR_tests_win64\tribler\Tribler\Test\Core\Upgrade\test_config_upgrade_70_71.py", line 33, in test_read_test_libtribler_conf
self.assertEqual(result_config.get_anon_proxy_settings(), (2, ("127.0.0.1", [5, 4, 3, 2, 1]), ''))
File "c:\python27\lib\unittest\case.py", line 513, in assertEqual
assertion_func(first, second, msg=msg)
File "c:\python27\lib\unittest\case.py", line 753, in assertTupleEqual
self.assertSequenceEqual(tuple1, tuple2, msg, seq_type=tuple)
File "c:\python27\lib\unittest\case.py", line 724, in assertSequenceEqual
self.fail(msg)
File "c:\python27\lib\unittest\case.py", line 410, in fail
raise self.failureException(msg)
AssertionError: Tuples differ: (2, ('127.0.0.1', [5, 4, 3, 2,... != (2, ('127.0.0.1', [5, 4, 3, 2,...

First differing element 2:
u'None'
''

- (2, ('127.0.0.1', [5, 4, 3, 2, 1]), u'None')
?                                     - ----

+ (2, ('127.0.0.1', [5, 4, 3, 2, 1]), '')

# Fixed code
def on_session_error(self, session, failure):
    """
    Handles the scenario of when a tracker session has failed by calling the
    tracker_manager's update_tracker_info function.
    Trap value errors that are thrown by e.g. the HTTPTrackerSession when a connection fails.
    And trap CancelledErrors that can be thrown when shutting down.
    :param failure: The failure object raised by Twisted.
    """
    failure.trap(ValueError, CancelledError, ConnectingCancelledError, RuntimeError)
    self._logger.warning(
        "Got session error for URL %s: %s", session.tracker_url, failure
    )

    self.clean_session(session)

    # Do not update if the connection got cancelled, we are probably shutting down
    # and the tracker_manager may have shutdown already.
    if failure.check(CancelledError, ConnectingCancelledError) is None:
        self.tribler_session.lm.tracker_manager.update_tracker_info(
            session.tracker_url, False
        )

    failure.tracker_url = session.tracker_url
    return failure