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

Fix deadlock in oath2 authentication #59557

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Commits on Nov 22, 2024

  1. Configuration menu
    Copy the full SHA
    23ce137 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    37576e5 View commit details
    Browse the repository at this point in the history
  3. Fix some warnings

    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    2d14eb9 View commit details
    Browse the repository at this point in the history
  4. Remove support for non-internal o2 library

    The internal copy of the o2 library has customisations and API
    changes which are required for QGIS... as a result it hasn't
    been possible to build with the non-internal library version
    for years.
    
    Remove all this dead/unused code.
    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    81d221c View commit details
    Browse the repository at this point in the history
  5. OAuth2 config cache should not be static

    We only ever create one instance of a QgsAuthMethod, so there's no need
    for this member to be static
    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    a18ea54 View commit details
    Browse the repository at this point in the history
  6. Protect config cache in QgsAuthOAuth2Method with read/write lock

    This is being accessed across multiple threads, so we need
    to protect access accordingly
    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    a353e70 View commit details
    Browse the repository at this point in the history
  7. Remove unused member

    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    5b37709 View commit details
    Browse the repository at this point in the history
  8. Simplify QgsAuthOAuth2Method::getOAuth2Bundle

    We do not need to use deleteLater here for QgsAuthOAuth2Config,
    so we can considerably simplify the logic
    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    a504af7 View commit details
    Browse the repository at this point in the history
  9. Avoid leak of QgsAuthOAuth2Config

    And make ownership clear by setting parent to the QgsO2 parent
    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    317a1fb View commit details
    Browse the repository at this point in the history
  10. Fix deadlock in oath2 authentication

    We have to take care that we don't directly create QgsO2 objects
    on the thread where the authentication request is occurring,
    as QgsO2 objects are long running but the thread requesting
    authentication may be short-lived. If we create QgsO2 objects
    on a short-running thread, then when we later try to
    authenticate using the same oauth2 authentication method we
    will get a deadlock, as the O2 reply server will no longer
    have an active thread or an event loop running.
    
    This was especially evident in browser items which use oauth2
    authentication. Since these are usually populated using very
    short-life threads, we'd often hit this situation:
    
    1. The connection would be expanded. Browser would create a thread
    to populate the connection. The oauth2 objects would then be created
    on this same thread, and everything would initially work OK. The
    user could complete the authentication since the browser population
    thread was blocked until this was done.
    2. The browser item got populated, and then the thread populating
    it was destroyed
    3. Later, something else would request authentication using the
    same oauth2 config. This may be eg the user expanding out a
    different folder on the browser connection.
    4. If the oauth2 token had expired, then we'd try to refresh it.
    But this relied on event-based logic, and the event loop for the
    QgsO2 object was no longer around to handle this. The authentication
    request would dead-lock.
    
    Fix this by ensuring that all QgsO2 objects are created and run on
    an instance of a new QgsOAuth2Factory QThread. This thread is created
    on demand, and will then exist for the life of the QGIS session.
    
    This ensures that all QgsO2 objects will run on a thread with an
    application-long lifetime, so there's no issue if they later
    require event-loop based logic (such as token refresh)
    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    e72e2b7 View commit details
    Browse the repository at this point in the history
  11. Ensure that O2 linkage is done in a thread-safe way

    We need to ensure that the link method is ONLY ever called from
    the QgsO2 object's thread, because it involves creation of
    child items and that is explicitly prohibited from external
    threads by Qt.
    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    a8116e9 View commit details
    Browse the repository at this point in the history
  12. Fix build

    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    58e0ff1 View commit details
    Browse the repository at this point in the history
  13. Fix instance

    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    c568a98 View commit details
    Browse the repository at this point in the history
  14. fix build

    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    b634c2a View commit details
    Browse the repository at this point in the history
  15. Fix warning

    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    c69bd89 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    a945d33 View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    13e40c8 View commit details
    Browse the repository at this point in the history
  18. Revert "Remove support for non-internal o2 library"

    This reverts commit 81d221c.
    nyalldawson committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    8c46b3e View commit details
    Browse the repository at this point in the history