Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError: local variable 'self' referenced before assignment #7867

Closed
sentry-for-tribler bot opened this issue Jan 29, 2024 · 8 comments
Closed
Assignees

Comments

@sentry-for-tribler
Copy link

Sentry Issue: TRIBLER-1JA

UnboundLocalError: local variable 'self' referenced before assignment
(1 additional frame(s) were not displayed)
...
  File "ipv8\taskmanager.py", line 131, in done_cb
  File "ipv8\taskmanager.py", line 18, in interval_runner
  File "tribler\core\components\libtorrent\download_manager\download_manager.py", line 828, in _invoke_states_cb
  File "tribler\core\components\libtorrent\download_manager\download_manager.py", line 839, in sesscb_states_callback
  File "tribler\core\components\libtorrent\torrentdef.py", line 236, in get_infohash
@xoriole xoriole added this to the 7.14.0 milestone Jan 29, 2024
@drew2a
Copy link
Contributor

drew2a commented Jan 30, 2024

Yesterday, @kozlovsky expressed suspicion that the issue could be related to the old Python version (3.8.4) used on our builder machines.

Perhaps it's a good time to upgrade it to 3.9?

@xoriole, is it easy to change the Python version on our builders? I can manage the change for GitHub actions.

Ref:

@xoriole
Copy link
Contributor

xoriole commented Jan 30, 2024

@drew2a I can try upgrading the builders today to 3.9.
For 3.10, we have a blocker.

Copy link
Author

sentry-for-tribler bot commented Feb 5, 2024

Sentry issue: TRIBLER-1JT for 7.13.1

[
Traceback (most recent call last):, 
  File "asyncio\events.py", line 81, in _run, 
  File "asyncio\proactor_events.py", line 162, in _call_connection_lost, 
OSError: [WinError 10038] Сделана попытка выполнить операцию на объекте, не являющемся сокетом
]

@kozlovsky
Copy link
Contributor

The last linked Sentry issue shows another unrelated case of UnboundLocalError:

UnboundLocalError: local variable 'exc_info' referenced before assignment
  File "tribler\core\components\libtorrent\download_manager\download.py", line 248, in process_alert
  File "tribler\core\components\libtorrent\download_manager\download.py", line 325, in on_tracker_error_alert
  File "__init__.py", line 1463, in error
  File "__init__.py", line 1570, in _log

Here, the error happens inside the code of the logging library:

    def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False,
             stacklevel=1):
        """
        Low-level logging routine which creates a LogRecord and then calls
        all the handlers of this logger to handle the record.
        """
        sinfo = None
        if _srcfile:
            #IronPython doesn't track Python frames, so findCaller raises an
            #exception on some versions of IronPython. We trap it here so that
            #IronPython can use logging.
            try:
                fn, lno, func, sinfo = self.findCaller(stack_info, stacklevel)
            except ValueError: # pragma: no cover
                fn, lno, func = "(unknown file)", 0, "(unknown function)"
        else: # pragma: no cover
            fn, lno, func = "(unknown file)", 0, "(unknown function)"
        if exc_info:  # <-- UnboundLocalError: local variable 'exc_info' referenced before assignment

The only reasonable explanation of how this can happen is memory corruption by a misbehaving C++ code.

Note that the error is inside the process_alert call. That looks suspicious because incorrect handling of ltsession.pop_alerts() is a possible reason for memory corruption (see #7886).

@kozlovsky
Copy link
Contributor

kozlovsky commented Mar 26, 2024

Another error:

SystemError: PyEval_EvalCodeEx: NULL globals
  File "asyncio\proactor_events.py", line 526, in _loop_writing
  File "asyncio\windows_events.py", line 522, in sendto
  File "asyncio\windows_events.py", line 734, in _register

Traceback is different, but the underlying reason should be the same: memory corruption

@kozlovsky
Copy link
Contributor

kozlovsky commented Mar 27, 2024

There is a chance #7945 can fix this problem. If not, then it is most probably libtorrent-related. My hope is that upgrading to Python 3.10, that is now possible, can fix the root reason of memory corruption problems.

Copy link

This issue has not seen activity for 60 days. It is now marked as stale. Please provide additional information or this issue may be closed in the future. We value your contribution and would love to hear more!

@qstokkink
Copy link
Contributor

The newest build implementation is now using Python 3.10. Looking at this discussion, this should be enough to resolve the various concerns listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants