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

Pass the number of the opened REST API port from Core to GUI #7251

Merged
merged 2 commits into from
Jan 10, 2023

Conversation

kozlovsky
Copy link
Contributor

@kozlovsky kozlovsky commented Jan 10, 2023

This PR is based on @xoriole's PR #7162 and fixes #7137. What is different is the way how GUI determines the opened API port. In the current PR, GUI takes the api_port value from the processes database.

Previously, EventRequestManager initially attempted to connect to the already running independently launched Core. Then in case a new Core process is started, EventRequestManager immediately starts repeated attempts to connect to it.

Now, EventRequestManager connects to the launched Core only after the Core REST API manager is started. Before that, CoreManager periodically attempts to read the api_port value from the processes database.

In case of a crash, the API port values (an initial value suggested by GUI and an actual value used by Core) are available in the error report as part of process information (in the last_processes section).

@kozlovsky kozlovsky marked this pull request as ready for review January 10, 2023 13:56
@kozlovsky kozlovsky requested review from a team, drew2a and xoriole and removed request for a team January 10, 2023 13:56
@@ -176,7 +223,7 @@ def stop(self, quit_app_on_core_finished=True):
if not self.core_connected:
# If Core is not connected via events_manager it also most probably cannot process API requests.
self._logger.warning('Core is not connected during the CoreManager shutdown, killing it...')
self.kill_core_process_and_remove_the_lock_file()
self.kill_core_process()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This renaming should actually be in the previous PR... When I extracted the current PR from the previous one, I missed this line...

@@ -65,6 +65,16 @@ def __init__(self, api_port, api_key, error_handler):
notifier.add_observer(notifications.tribler_shutdown_state, self.on_tribler_shutdown_state)
notifier.add_observer(notifications.report_config_error, self.on_report_config_error)

def create_request(self) -> QNetworkRequest:
url = QUrl("http://localhost:%d/events" % self.api_port)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT

Suggested change
url = QUrl("http://localhost:%d/events" % self.api_port)
url = QUrl(f'http://localhost:{self.api_port}/events')

Determines the actual REST API port of the Core process.

This function is first executed from the `on_core_started` after the physical Core process starts and then
repeatedly executed after API_PORT_CHECK_INTERVAL seconds until it retrieves the REST API port value from
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"after API_PORT_CHECK_INTERVAL seconds" --> to avoid any confusion, this is in milliseconds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants