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

Proper shutdown of aiohttp.web_runner.AppRunner by RESTManager #7217

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/tribler/core/components/restapi/rest/rest_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import ssl
import traceback
from typing import Optional

from aiohttp import web
from aiohttp.web_exceptions import HTTPNotFound
Expand Down Expand Up @@ -73,9 +74,9 @@ def __init__(self, config: APISettings, root_endpoint: RootEndpoint, state_dir=N
super().__init__()
self._logger = logging.getLogger(self.__class__.__name__)
self.root_endpoint = root_endpoint
self.runner = None
self.site = None
self.site_https = None
self.runner: Optional[web.AppRunner] = None
self.site: Optional[web.TCPSite] = None
self.site_https: Optional[web.TCPSite] = None
self.config = config
self.state_dir = state_dir

Expand Down Expand Up @@ -152,14 +153,7 @@ async def start(self):
self._logger.info("Started HTTPS REST API: %s", self.site_https.name)

async def stop(self):
"""
Stop the HTTP API and return a deferred that fires when the server has shut down.
"""
self._logger.info('Stop')

if self.site:
await self.site.stop()
if self.site_https:
await self.site_https.stop()
# Should the next line be used instead of the above lines?
# await self.runner.cleanup()
if self.runner:
await self.runner.shutdown() # should be called before self.runner.cleanup()
await self.runner.cleanup() # self.site.stop() is called inside this method