Skip to content

[MOB-11764] Fix JWT refresh timer race condition on app background #929

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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

sumeruchat
Copy link
Collaborator

@sumeruchat sumeruchat commented Jul 24, 2025

Problem

Customer reported JWT refresh timer not being cleared when app goes to background after null JWT token is returned, potentially causing hanging timers and unnecessary retry attempts.

Root Cause

Race condition between:

  • scheduleAuthTokenRefresh() (executor thread) - schedules retry timer when JWT returns null
  • clearRefreshTimer() (activity lifecycle thread) - clears timer on app background

If app backgrounds immediately after null JWT response, timer creation and clearing could race, leaving uncanceled timers.

Solution

  • Synchronized scheduleAuthTokenRefresh() and clearRefreshTimer() methods
  • Ensures timer operations are atomic and thread-safe
  • Made isTimerScheduled visible for testing with @VisibleForTesting

Testing

New test: testNullJWTRefreshTimerRaceConditionOnBackground
All auth tests pass (24/24)
Full test suite passes (200+ tests)
No regressions

Manual Test Case

  1. Setup: Configure auth handler to return null JWT
  2. Trigger: Set user email to start auth flow
  3. Background: Immediately background app during auth retry
  4. Verify: No hanging timers continue firing after app backgrounds
  5. Foreground: Bring app to foreground - should cleanly restart auth

Impact

  • Fixes: Hanging JWT refresh timers on app background
  • Improves: App lifecycle management during auth failures
  • Minimal: Thread-safe synchronization, no functional changes

Fixes MOB-11764

…date test class and method references from `IterableApiTest` to `IterableKeychainTest`.- Ensure full package paths are used in test commands for consistency.- Simplify test result parsing logic in `agent_test.sh`.- Enhance error reporting for failed builds and tests.- Improve README instructions for running specific tests.
…sh` to `build.sh` and `agent_test.sh` to `test.sh` for uniformity.- Updated all references in documentation and scripts.
…eal-time progress display for Gradle tasks and tests.- Improve test filtering with wildcard support.- Include detailed logging for test events and exceptions.- Simplify build task output and handle build status.- Refactor cleanup and error handling for robustness.
…ensure JWT token refresh timer is cleared when app goes to background.- Ensure synchronization to prevent race conditions during timer operations.- Verify
- Synchronize scheduleAuthTokenRefresh and clearRefreshTimer methods
- Prevents race condition when null JWT schedules retry timer but app backgrounds immediately
- Ensures timer creation and clearing are atomic operations
- Add test case to verify fix works correctly

Fixes MOB-11764
@sumeruchat sumeruchat marked this pull request as draft July 24, 2025 15:47
@Ayyanchira
Copy link
Member

@sumeruchat , is this branch and PR also for solving the same JWT in background issue? Should we close this one?

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.

2 participants