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

[main] Long Tribler's shutdown #7314

Closed
drew2a opened this issue Mar 10, 2023 · 3 comments · Fixed by #7315
Closed

[main] Long Tribler's shutdown #7314

drew2a opened this issue Mar 10, 2023 · 3 comments · Fixed by #7315
Assignees
Milestone

Comments

@drew2a
Copy link
Contributor

drew2a commented Mar 10, 2023

Describe the bug
During the Tribler's shutdown, it freezes on this line:

await self.runner.cleanup() # self.site.stop() is called inside this method

To Reproduce
Steps to reproduce the behavior:

  1. Open Tribler
  2. Close Tribler

Screenshots
image

Additional context
The bug doesn't reproduce while running Tribler headless.

@drew2a drew2a added this to the 7.13.0 milestone Mar 10, 2023
@drew2a
Copy link
Contributor Author

drew2a commented Mar 10, 2023

Going deeper... The freeze happens here:

https://github.com/aio-libs/aiohttp/blob/3ff81dc9c9ce20efd3bf54cf52adaf438c483a92/aiohttp/web_protocol.py#L287-L288

                if self._task_handler is not None and not self._task_handler.done():
                    await self._task_handler

With the following value of self._task_handler:

Wait for  <Task pending name='Task-108' coro=<RequestHandler.start() running at /Users/<user>/Projects/github.com/Tribler/tribler/venv/lib/python3.9/site-packages/aiohttp/web_protocol.py:513>
wait_for=<Task pending name='Task-109' coro=<RequestHandler._handle_request() running at /Users/<user>/Projects/github.com/Tribler/tribler/venv/lib/python3.9/site-packages/aiohttp/web_protocol.py:434>
wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x10ec27a30>()]> cb=[<TaskWakeupMethWrapper object at 0x10eb73eb0>()]>>

@drew2a
Copy link
Contributor Author

drew2a commented Mar 10, 2023

The bug started to appear after merge #7300

@drew2a drew2a self-assigned this Mar 10, 2023
@kozlovsky
Copy link
Contributor

As I understand it, the actual reason for the freezing is here:

class EventsEndpoint(RESTEndpoint):
    ...
    async def get_events(self, request):
        ...
        try:
            while True:
                await asyncio.sleep(3600)  # <-- here
        except CancelledError:
            self.events_responses.remove(response)
            return response

The EventsEndpoint response is a stream that never finishes. The response handling code even does not have a code path to finish the response during the shutdown. Also, the code eats and does not reraise the CancelledError exception, and that does not look good to me. I think the correct code should look like this:

class EventsEndpoint(RESTEndpoint):
    ...
    async def get_events(self, request):
        ...
        try:
            while not self._shutdown:
                await asyncio.sleep(1)
        finally:
            self.events_responses.remove(response)
        return response

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

Successfully merging a pull request may close this issue.

2 participants