Skip to content

Race condition in token validation when choosing between multiple GHES #10014

Closed

Description

@qasic

Description

I built the latest Refined GitHub source, and the token validation icon often shows invalid when switching between multiple GHES domains.

How to replicate the issue + URL

Note: This describes the behaviour of the development version at 26d6ce8

  1. Open your browser's development tools
  2. Enable Refined Github on first GHES domain
  3. Enable Refined Github on second GHES domain
  4. Open the Options page for Refined GitHub
  5. In the Domain Selector, choose the first GHES instance
  6. Enter the token. It's validated
  7. In the Domain Selector, choose the second GHES instance
  8. The token field shows invalid. Enter the token. It's validated
  9. In the Domain Selector, choose the first GHES instance
  10. Notice that the validation field shows invalid, even though an expiry time is present on the token

Extension version

26d6ce8

Browser(s) used

Google Chrome 152.0.7977.64 (Official Build) (64-bit) (cohort: 152.0.7977.64 Rollout)

Token ⚠️

  • I set a token in the options page. I understand that some features require a token to work.

Activity

  1. qasic commented on Aug 29, 2026

    @qasic
    Author
  2. fregante commented on Aug 29, 2026

    @fregante
    Member

    No direct OptionsSync access allowed. The plan is to improve OptionsSync itself to allow widget updates and remove the additional glue.

    So either this is fixed in OptionsSync or some more glue is added to avoid race conditions.

  3. fregante commented on Aug 29, 2026

    @fregante
    Member
    • PAT token input saves are saved and debounced through syncForm, so a pending save could run after the selector had loaded another domain's values. The callback then read the updated form but wrote it through the previous domain's storage instance.

    Doubtful. The delay 300ms, you can hardly paste a token and make a domain change before that's done even if you tried.

    • A separate validation race also occurred. The selected host changed before its PAT finished loading. The validation effect sent the previous PAT to the new host via both getTokenInfo and tokenUser, resulting in two HTTP 401 responses. Validation ran again with the correct PAT after storage loading completed.

    Validation has nothing to do with data being saved to the form, so it most certainly can't be the cause of it.

    Sounds like the title of this issue doesn't match the contents.

  4. fregante commented on Aug 29, 2026

    @fregante
    Member

    I think what you're seeing is this:

    1. The component's host attribute is updated immediately, triggering a fetch request with the stale input value
    2. OptionsSync takes a moment to read from storage, set the input value and trigger an input event

    I don’t think this caused data loss but it definitely causes one extra fetch.

    Assuming that Svelte is handling these promises correctly, it shouldn't really cause issues other than a visual flicker caused by the token being sent to the wrong instance.

  5. qasic commented on Aug 29, 2026

    @qasic
    Author

    Thanks for the really quick reply. I wasn't expecting one on the weekend. I think I got too blindsided by my experience in #8428.

    You're right - the persistence was absolutely fine; only the token validator was showing an invalid status. I'll update the title, description, and reproduction to be consistent with this.

    The bug is in the token validator's async lifecycle. A domain change can start validation with the previous domain's token, and that stale request can finish after the correct validation and overwrite the <span> with invalid.

    Adding a guard to check the previous results seems to have fixed it 😄

  6. changed the title [-]Person Access Token aren't persisted for multiple GHES[/-] [+]Race condition when validating tokens domain selector has 2+ GHES[/+] on Aug 29, 2026
  7. changed the title [-]Race condition when validating tokens domain selector has 2+ GHES[/-] [+]Race condition in token validation when domain selector has 2+ GHES[/+] on Aug 29, 2026
  8. changed the title [-]Race condition in token validation when domain selector has 2+ GHES[/-] [+]Race condition in token validation when choosing between multiple GHES[/+] on Aug 29, 2026
  9. qasic commented on Aug 31, 2026

    @qasic
    Author

    @fregante I noticed labeled this "under discussion". Are there any other points to discuss? Unfortunately, I can't upload a video for the issue because it would expose the corporate domain hosts.

    Otherwise, I can put up a PR for this after further testing this week.

  10. fregante commented on Aug 31, 2026

    @fregante
    Member

    PR welcome. What's up for discussion is how to fix it and whether it's worth it. A simple debounce would work already but I don't want to lose the immediate feedback when pasting a token.

  11. added 2 commits that reference this issue on Sep 5, 2026
    bfa5ceb
    b417e97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions