← 输入框|github.com|刷新
Skip to content

fix(session): offload JWKS lookup from event loop in AsyncSession - #781

Open
shafiktanbir wants to merge 1 commit into
workos:mainfrom
shafiktanbir:fix/async-session-jwks-offload
Open

shafiktanbir wants to merge 1 commit into
workos:mainfrom
shafiktanbir:fix/async-session-jwks-offload

Conversation

@shafiktanbir

Copy link
Copy Markdown

Description

Fixes #780

AsyncSession.refresh() and AsyncSession.get_logout_url() called synchronous PyJWKClient.get_signing_key_from_jwt(), which performs a blocking HTTP fetch via urllib on a cold or expired JWKS cache directly on the asyncio event loop thread.

  • Offload self.jwks.get_signing_key_from_jwt via asyncio.to_thread inside AsyncSession.refresh().
  • Add AsyncSession._authenticate_async() using asyncio.to_thread and call it from AsyncSession.get_logout_url(), while keeping synchronous AsyncSession.authenticate() unchanged.
  • Extract shared cookie unsealing and token claim decoding helpers on AsyncSession.
  • Add loopback HTTP tests in tests/test_session.py verifying another asyncio task runs while a slow JWKS fetch is in flight for both refresh() and get_logout_url().

Verified locally with ruff format --check ., ruff check ., pyright (0 errors), and pytest tests/test_session.py (67 passed).

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

@shafiktanbir
shafiktanbir requested a review from a team as a code owner November 23, 2026 03:46
@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Moves blocking JWKS lookups off the event loop in AsyncSession.refresh() and AsyncSession.get_logout_url().

  • Async session refresh and logout keep the event loop running.

Reviews (1) · Last reviewed commit: "fix(session): offload JWKS lookup from e..." · Reviewed by Greptile

This branch has not been deployed

No deployments
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.

AsyncSession refresh and logout block the event loop on JWKS cache misses

1 participant