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

ERROR Slow coroutine step execution (duration=1.673 seconds): <Task pending name='TorrentChecker:check local torrents' #7784

Closed
slrslr opened this issue Dec 18, 2023 · 2 comments · Fixed by #7876
Assignees

Comments

@slrslr
Copy link

slrslr commented Dec 18, 2023

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. start Tribler with some torrents
  2. check tribler-core-error.log
  3. See error:
[tribler-core PID:39] 2023-12-18 06:51:58,923 - ERROR <watching_thread:91> tribler.core.utilities.slow_coro_detection._report_freeze(): Slow coroutine is occupying the loop for 1.206 seconds already: <Task pending name='TorrentChecker:check local torrents' coro=<interval_runner() running at ipv8/taskmanager.py:18> cb=[TaskManager.register_task.<locals>.done_cb() at ipv8/taskmanager.py:128]>
Stack for <Task pending name='TorrentChecker:check local torrents' coro=<interval_runner() running at ipv8/taskmanager.py:18> cb=[TaskManager.register_task.<locals>.done_cb() at ipv8/taskmanager.py:128]> (most recent call last):
  File "run_tribler.py", line 109, in <module>
  File "tribler/core/start_core.py", line 204, in run_core
  File "tribler/core/start_core.py", line 174, in run_tribler_core_session
  File "asyncio/base_events.py", line 603, in run_until_complete
  File "asyncio/base_events.py", line 570, in run_forever
  File "asyncio/base_events.py", line 1859, in _run_once
  File "tribler/core/utilities/slow_coro_detection/patch.py", line 37, in patched_handle_run
  File "asyncio/events.py", line 81, in _run
  File "ipv8/taskmanager.py", line 18, in interval_runner

[tribler-core PID:39] 2023-12-18 06:51:59,390 - ERROR <patch:52> tribler.core.utilities.slow_coro_detection._report_long_duration(): Slow coroutine step execution (duration=1.673 seconds): <Task pending name='TorrentChecker:check local torrents' coro=<interval_runner() running at ipv8/taskmanager.py:18> wait_for=<_GatheringFuture pending cb=[<TaskWakeupMethWrapper object at 0x7f3d63a8e160>()]> cb=[TaskManager.register_task.<locals>.done_cb() at ipv8/taskmanager.py:128]>

Desktop (please complete the following information):

  • OS: Linux Debian 11 oldstable
  • Tribler's version 7.13.0 (flatpak org.tribler.Tribler)
@qstokkink
Copy link
Contributor

qstokkink commented Dec 18, 2023

Thanks for your report. It seems like there is a heavy database operation running on a thread where it does not belong, on the "main thread".

This will not crash Tribler nor is there any unrecoverable error (@Tribler/reviewers perhaps we should downgrade this to "WARNING" level). That said, this is not good for your client's responsiveness.

The rest of my answer is targeted at developers. This is the code being called in the interval task:

async def check_local_torrents(self) -> Tuple[List, List]:
"""
Perform a full health check on a few popular and old torrents in the database.
"""
selected_torrents = self.torrents_to_check()
self._logger.info(f'Check {len(selected_torrents)} local torrents')
coros = [self.check_torrent_health(t.infohash) for t in selected_torrents]
results = await gather_coros(coros)
self._logger.info(f'Results for local torrents check: {results}')
return selected_torrents, results

This is database code and it should be called on a separate thread (e.g., using run_threaded()).

@qstokkink
Copy link
Contributor

I closed my quick fix of #7796. With the interweaving of asyncio and db calls, it's probably best to solve this in (or, wait for) a big refactoring of the entire torrent checker architecture.

@drew2a drew2a self-assigned this Feb 1, 2024
@drew2a drew2a added this to the 7.14.0 milestone Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants