Skip to content

TokenFetcher: Replace optimistic locking with pessimistic locking - #24857

Open
NobodysNightmare wants to merge 1 commit into
devfrom
oauth-pessimistic-locking
Open

TokenFetcher: Replace optimistic locking with pessimistic locking#24857
NobodysNightmare wants to merge 1 commit into
devfrom
oauth-pessimistic-locking

Conversation

@NobodysNightmare

Copy link
Copy Markdown
Contributor

Changing locking mode in the TokenFetcher. Instead of locking optimistically around the update of the stored values, we'll lock pessimistically around the entire fetching of an access token — even if no refresh happens.

This avoids concurrent refreshes of the same token entirely, which can be beneficial if the OAuth server invalidates a refresh token after using it. The old approach may have led to rejected refreshes in such cases, while the new approach ensures that exactly one refresh will happen.

Ticket

https://community.openproject.org/wp/SI-238

@NobodysNightmare
NobodysNightmare force-pushed the oauth-pessimistic-locking branch from 130f6fa to 5f8f671 Compare August 21, 2026 06:16
@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./modules/backlogs/spec/features/inbox_column_spec.rb[1:7:1]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #24857, linked for reference only):

- `rspec ./modules/backlogs/spec/features/inbox_column_spec.rb[1:7:1]`

Treat this as a standalone task, unrelated to PR #24857. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #24857 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @NobodysNightmare to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @NobodysNightmare, and request a review from @NobodysNightmare.
On every commit, set @NobodysNightmare as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@NobodysNightmare
NobodysNightmare force-pushed the oauth-pessimistic-locking branch from 5f8f671 to eebe60d Compare August 21, 2026 07:15
Changing locking mode in the TokenFetcher.
Instead of locking optimistically around the update of the stored
values, we'll lock pessimistically around the entire fetching of
an access token — even if no refresh happens.

This avoids concurrent refreshes of the same token entirely, which
can be beneficial if the OAuth server invalidates a refresh token after
using it. The old approach may have led to rejected refreshes in such cases,
while the new approach ensures that exactly one refresh will happen.
@NobodysNightmare
NobodysNightmare force-pushed the oauth-pessimistic-locking branch from eebe60d to 8240701 Compare August 21, 2026 08:12
@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./spec/features/work_packages/table/switch_types_spec.rb[1:1:1]
  • rspec ./spec/features/workflows/edit_spec.rb[1:4:4]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #24857, linked for reference only):

- `rspec ./spec/features/work_packages/table/switch_types_spec.rb[1:1:1]`
- `rspec ./spec/features/workflows/edit_spec.rb[1:4:4]`

Treat this as a standalone task, unrelated to PR #24857. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #24857 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @NobodysNightmare to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @NobodysNightmare, and request a review from @NobodysNightmare.
On every commit, set @NobodysNightmare as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@NobodysNightmare
NobodysNightmare requested a review from a team August 21, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant