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

[Flatpak][7.13.0] CoreConnectionError: "The connection to the Tribler Core was lost" in event_request_manager.on_error #7603

Closed
kozlovsky opened this issue Sep 18, 2023 · 7 comments
Assignees
Milestone

Comments

@kozlovsky
Copy link
Contributor

kozlovsky commented Sep 18, 2023

https://sentry.tribler.org/organizations/tribler/issues/2003/events/de644ea355b040ba95b14ae230256a88/

The error looks strange; I spent quite some time trying to figure it out. The following is how I understand what is going on:

  1. A user tries to close the Tribler GUI.

  2. TriblerWindow.close_tribler() is called.

  3. TriblerWindow.close_tribler() method calls self.core_manager.stop():

    class CoreManager(QObject):
        ...
        def stop(self, quit_app_on_core_finished=True):
            if self.shutting_down:
                return
    
            self.shutting_down = True
            self._logger.info("Stopping Core manager")  # 4
    
            if self.core_process and not self.core_finished:
                if not self.core_connected:
                    ...
                self.events_manager.shutting_down = True  # 5
    
                def send_shutdown_request(initial=False):
                    if initial:
                        self._logger.info(f"Sending {SHUTDOWN_ENDPOINT} request to Tribler Core")  # 6
                    else:
                        self._logger.warning(f"Re-sending {SHUTDOWN_ENDPOINT} request to Tribler Core")
                    ...
                send_shutdown_request(initial=True)
        ```
  4. You can see the 'Stopping Core manager' message in the log, so the line marked as #4 is executed.

  5. The line #5 that sets the events_manager.shutting_down flag to True should also be executed because...

  6. ...in the log, you can see the message from the line #6, "Sending shutdown request to Tribler Core".

So, based on log messages, I'm sure that the flag events_manager.shutting_down should be set to True before the shutdown request to Core is performed.

But then, the actual error happens in the on_error method of the event manager:

class EventRequestManager(QNetworkAccessManager):
    ...
    def on_error(self, error: int, reschedule_on_err: bool):
        if self.shutting_down:
            return

        if self.receiving_data:
            raise CoreConnectionError('The connection to the Tribler Core was lost')    

You can see from the code that EventManager should raise CoreConnectionError only when self.shutting_down is not set to True. But in the current case, as we just seen, it should be set to True. So, currently, I do not understand how this error is possible.

Does anybody have any idea how this error can happen?

@kozlovsky kozlovsky added this to the 7.14.0 milestone Sep 18, 2023
@sentry-for-tribler
Copy link

Sentry issue: TRIBLER-141

@kozlovsky kozlovsky assigned kozlovsky and xoriole and unassigned kozlovsky Sep 25, 2023
@xoriole
Copy link
Contributor

xoriole commented Oct 6, 2023

This issue has been reported on multiple platforms, however, I was able to reproduce it on Linux using the Flatpak build. Using the Flatpak build, it was possible to run multiple instances of Tribler. Each of those instances created separate GUI and core processes but with the same PID (because of the Flatpak sandbox environment). Since the state directory is shared among the instances, all Tribler instances connect to the first running core. Then, shutting down one of the GUI instances also kills the only running core used by all the GUI instances. This results in the other Tribler instances failing to connect to the Core which raise this reported issue.

@sentry-for-tribler
Copy link

Sentry issue: TRIBLER-1CY

@drew2a drew2a modified the milestones: 7.14.0, 7.13.1 Oct 9, 2023
@synctext
Copy link
Member

synctext commented Oct 9, 2023

Can we add additional Sentry reporting to confirm these suspicions?

Great addition to our debug chain if we finally nail this mysterious error. The above is a bit cryptic to me, but the suspicion is that this error reported by 39 unique Sentry users is all just a close Tribler gone wrong ???TriblerWindow.close_tribler()

@sentry-for-tribler
Copy link

Sentry issue: TRIBLER-1DW

@kozlovsky kozlovsky changed the title [Mysterious error][7.13.0] CoreConnectionError: "The connection to the Tribler Core was lost" in event_request_manager.on_error [Flatpak][7.13.0] CoreConnectionError: "The connection to the Tribler Core was lost" in event_request_manager.on_error Dec 4, 2023
@drew2a
Copy link
Contributor

drew2a commented Dec 4, 2023

As far as I understand the following explanation by @xoriole:

This issue has been reported on multiple platforms, however, I was able to reproduce it on Linux using the Flatpak build. Using the Flatpak build, it was possible to run multiple instances of Tribler. Each of those instances created separate GUI and core processes but with the same PID (because of the Flatpak sandbox environment). Since the state directory is shared among the instances, all Tribler instances connect to the first running core. Then, shutting down one of the GUI instances also kills the only running core used by all the GUI instances. This results in the other Tribler instances failing to connect to the Core which raise this reported issue.

The issue should be solved by @kozlovsky in

Am I right?

@xoriole
Copy link
Contributor

xoriole commented Dec 11, 2023

As this issue is renamed to be Flatpak specific which is fixed, we can close this issue. I have created a new issue specific to Windows issue here: #7772

@xoriole xoriole closed this as completed Dec 11, 2023
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