Skip to content

Destroyed AuthenticationActivity retained by CustomTabsController.authTabLauncher (4.1.0; unchanged in 5.0.0-beta.0) #1093

Open

Description

@GGRichardson

Description

CustomTabsController can retain a destroyed AuthenticationActivity through its authTabLauncher and activity result registry after browser authentication has ended and service unbinding has run.

Observed at runtime on Auth0.Android 4.1.0. Reporting for consideration in 5.0.0-beta.0 because its CustomTabsController.java is byte-identical to 4.1.0 (Git blob f8c484692ebcc0c4da307058244814a52bae2a64). We have not reproduced this on a running 5.0.0-beta.0 build.

Expected: destroyed authentication activities should become collectible after cleanup, even if native browser callbacks temporarily retain the service connection/controller.

Reproduction / observed workflow

Observed in an integrating Android application, not yet reduced to the official sample app. Exact minimal reproduction and frequency remain unconfirmed.

  1. Start hosted browser sign-in using WebAuthProvider with Chrome available.
  2. Exercise browser cancellation and a subsequent sign-in, with portrait/landscape rotation in the native app and during browser authentication.
  3. Complete or cancel authentication, then background the app and inspect LeakCanary.

The baseline heap captured this chain after activity destruction:

GC root: global variable in native code
CustomTabsClient$3.this$0
  -> CustomTabsServiceConnection$1.this$0
  -> CustomTabsController.authTabLauncher
  -> ActivityResultRegistry$register$2.this$0
  -> ComponentActivity$activityResultRegistry$1.this$0
  -> destroyed com.auth0.android.provider.AuthenticationActivity

Retained: 41,693 bytes / 603 objects
Retained duration: 505,682 ms
LeakCanary signature: e9b26f477f8329d40efcd1423486f13912bac553

The presence of authTabLauncher in the retained chain does not by itself mean the browser was launched in Auth Tab mode; the tested launch log reported the Custom Tabs path.

Proposed lifecycle cleanup and local verification

We tested a source-pinned 4.1.0 modification limited in production behavior to CustomTabsController:

  • During the existing owner's destruction/unbind path, release the Auth Tab launcher, TWA launcher, session references, and weak context.
  • Make teardown idempotent, balance service-binding attempts, and destroy the detached TWA launcher.
  • Mark the controller closed and reject late service connections or queued browser launches after closure.
  • Keep the existing activity lifecycle, callback recovery, PKCE, and token behavior intact. No reflection, forced browser termination, or suppression of leak detection.

After this modification, the same physical tablet passed browser-X cancellation, native rotation, browser rotation, and successful hosted sign-in returning to the native app. A fresh, user-requested LeakCanary heap analysis reported 0 application leaks, 0 library leaks, and 0 unreachable objects. The original one-leak report was retained in history.

Local automated verification: 25 controller tests plus 37 consuming-app authorization/setup tests passed; debug lint and APK assembly passed. This is bounded evidence, not a claim that every lifecycle path is leak-free.

Could maintainers confirm whether clearing these activity-owned references belongs in the controller's unbind/destruction cleanup and consider an upstream fix for this retention path?

Version comparison

Environment

  • Auth0.Android: 4.1.0 runtime reproduction; 5.0.0-beta.0 source comparison only.
  • Android 14 / API 34, Samsung SM-T220 physical tablet.
  • Browser: Chrome (exact browser version not captured in this report).
  • LeakCanary 2.14.

No heap dump is attached because it may contain credentials or other sensitive application data. Open issues were searched for CustomTabsController and leak; no matching open issue was found. Official-sample reproduction and the remaining template checklist checks have not been completed.

Activity

  1. pmathew92 commented on Oct 14, 2026

    @pmathew92
    Member

    Hi @GGRichardson , Thanks for reporting this issue. We will investigate this and get back.

    Observed in an integrating Android application, not yet reduced to the official sample app. Exact minimal reproduction and frequency remain unconfirmed.

    1. Start hosted browser sign-in using WebAuthProvider with Chrome available.
    2. Exercise browser cancellation and a subsequent sign-in, with portrait/landscape rotation in the native app and during browser authentication.
    3. Complete or cancel authentication, then background the app and inspect LeakCanary.

    Want to confirm the above steps were done with AuthTab and not via normal custom tabs ?

  2. GGRichardson commented on Oct 14, 2026

    @GGRichardson
    Author

    Thanks for investigating. Our integration uses WebAuthProvider.login(...).start(...) without explicitly calling .withAuthTab().

    The LeakCanary trace shows this retention path:

    CustomTabsController.authTabLauncher → ActivityResultRegistry → destroyed AuthenticationActivity

    That field name was the basis for identifying the retained reference—not confirmation that the browser actually launched in AuthTab mode.

    Would you expect that launcher reference to be registered and retained even when normal Custom Tabs are used? Please let us know the preferred way to confirm the actual launch mode, and we can verify it during reproduction.

    Thanks,
    Greg

  3. pmathew92 commented on Oct 15, 2026

    @pmathew92
    Member

    Could you share your testing device details: device model , OS version and the chrome browser version.

  4. GGRichardson commented on Oct 15, 2026

    @GGRichardson
    Author

    Hi, the leak has been observed on both testing devices:

    Device model Android OS Chrome version
    Samsung SM-T220 Android 14 (API 34) 154.0.8037.127
    Samsung SM-X210 Android 16 (API 36) 155.0.8059.39

    These versions were read directly from both devices today, October 15, 2026. They are the currently installed versions; we have not confirmed whether the Chrome versions were identical at the time of the original leak captures.

    Thanks,
    Greg

  5. GGRichardson commented on Oct 15, 2026

    @GGRichardson
    Author

    Following up on the version caveat in my previous comment: I can confirm that the Chrome versions listed in the table were used during testing on the respective devices:

    • Samsung SM-T220: Android 14 (API 34), Chrome 154.0.8037.127
    • Samsung SM-X210: Android 16 (API 36), Chrome 155.0.8059.39

    The leak was observed on both devices.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions