Skip to content

SG-33297 Fix race condition on the login UX#1095

Open
carlos-villavicencio-adsk wants to merge 2 commits intomasterfrom
ticket/SG-33297_fix_race_condition_login_ux
Open

SG-33297 Fix race condition on the login UX#1095
carlos-villavicencio-adsk wants to merge 2 commits intomasterfrom
ticket/SG-33297_fix_race_condition_login_ux

Conversation

@carlos-villavicencio-adsk
Copy link
Copy Markdown
Contributor

Summary

Fix a race condition in LoginDialog that caused the 3-fields credentials UI (host / login / password) to appear briefly — or permanently on slow / Windows systems — even when the target site uses Autodesk Identity or SSO.

Root Cause

_toggle_web() was wired exclusively to the QThread.finished signal of the background site-info query task. Qt cross-thread signals are delivered through the event queue: the slot only runs once the event loop is spinning.

Because the constructor calls wait() to block until the thread finishes, then returns before the event loop has started, the finished signal sits undelivered in the queue. The dialog opens with the hard-coded default METHOD_BASIC (3-fields form). Only after exec_() / show() kick the event loop does _toggle_web fire and correct the UI — far too late, and unreliable under timing pressure (Windows scheduler, cold cache, slow network).

Fix

python/tank/authentication/login_dialog.py

Call _toggle_web() synchronously immediately after wait() returns, while still in the constructor. The site-info data is already populated at that point, so the dialog opens with the right UI state (web-login / ASL) before any pixels are painted.

Test

The test constructs a LoginDialog for an oxygen (Autodesk Identity) site and asserts method_selected != METHOD_BASIC before any processEvents() call, directly reproducing the pre-fix failure window:

ld = login_dialog.LoginDialog(
    is_session_renewal=True,
    hostname="https://identity.shotgunstudio.com",
)
# No processEvents() — simulates the dialog not yet having been shown.
self.assertNotEqual(ld.method_selected, auth_constants.METHOD_BASIC)
self.assertEqual(ld.method_selected, auth_constants.METHOD_WEB_LOGIN)
self.assertFalse(ld.ui.login.isVisible())
self.assertFalse(ld.ui.password.isVisible())

Without the fix this test fails (value is METHOD_BASIC); with the fix it passes deterministically regardless of Qt event-loop timing.

Notes

  • The QThread.finished → _toggle_web signal connection is preserved for subsequent URL changes typed into the site field during an active session; only the initial synchronous call is new.
  • SGTK_FORCE_STANDARD_LOGIN_DIALOG and all other existing overrides continue to work unchanged — the guard in _toggle_web handles them.
  • This bug was more visible on Windows and after cache purges because both increase the gap between wait() returning and the first event-loop tick.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.43%. Comparing base (5d4ea39) to head (a8ab6e7).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1095   +/-   ##
=======================================
  Coverage   79.43%   79.43%           
=======================================
  Files         198      198           
  Lines       20749    20750    +1     
=======================================
+ Hits        16482    16483    +1     
  Misses       4267     4267           
Flag Coverage Δ
Linux 78.89% <100.00%> (+<0.01%) ⬆️
Python-3.10 79.25% <100.00%> (+0.01%) ⬆️
Python-3.11 79.15% <100.00%> (+<0.01%) ⬆️
Python-3.13 79.15% <100.00%> (+<0.01%) ⬆️
Python-3.9 79.21% <100.00%> (-0.01%) ⬇️
Windows 78.93% <100.00%> (+<0.01%) ⬆️
macOS 78.90% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an event-loop timing race in LoginDialog where the dialog could initially render the legacy 3-field credentials UI before the background site-info query’s QThread.finished signal was dispatched, causing incorrect UI selection for Identity/SSO sites (especially on slower/Windows systems).

Changes:

  • Call _toggle_web() synchronously in LoginDialog.__init__ after the background query wait() returns, so the initial UI mode is set before the dialog is shown.
  • Add a regression test that asserts method_selected is not METHOD_BASIC before any processEvents() call for an Autodesk Identity (“oxygen”) site.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
python/tank/authentication/login_dialog.py Invokes _toggle_web() immediately after the initial site-info query wait to avoid relying on queued cross-thread signal delivery.
tests/authentication_tests/test_interactive_authentication.py Adds a regression test covering the pre-event-loop window where the wrong UI mode could be selected.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread python/tank/authentication/login_dialog.py
Comment thread tests/authentication_tests/test_interactive_authentication.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@carlos-villavicencio-adsk carlos-villavicencio-adsk requested a review from a team May 6, 2026 23:42
Copy link
Copy Markdown
Member

@julien-lang julien-lang left a comment

Choose a reason for hiding this comment

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

Wow! Great job @carlos-villavicencio-adsk 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants