Skip to content
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

Possible memory leak during authentication #686

Closed
6 tasks done
jbsohn opened this issue Sep 13, 2023 · 2 comments
Closed
6 tasks done

Possible memory leak during authentication #686

jbsohn opened this issue Sep 13, 2023 · 2 comments
Labels
bug This points to a verified bug in the code

Comments

@jbsohn
Copy link

jbsohn commented Sep 13, 2023

Checklist

Description

After the Auth0 login is shown LeakCanary is logging a small memory leak. I have recreated the issue in a small sample app. I have included the MainActivity in the Reproduction field below. The leak-canary.log attached to this issue has the details. If we roll back to version 2.8.1 we are not seeing the issue.

leak-canary.log

Reproduction

I created a new Android app from template with this code in the MainActivity:

package com.example.auth0memtest

import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.auth0.android.Auth0
import com.auth0.android.authentication.AuthenticationException
import com.auth0.android.callback.Callback
import com.auth0.android.provider.WebAuthProvider
import com.auth0.android.result.Credentials


class MainActivity : AppCompatActivity() {

    private lateinit var account: Auth0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        account = Auth0(
            "TODO",
            "TODO"
        )

        setContentView(R.layout.activity_main)

        val button = findViewById<View>(R.id.button) as Button
        button.setOnClickListener { loginWithBrowser() }
    }

    private fun loginWithBrowser() {
        // Setup the WebAuthProvider, using the custom scheme and scope.

        WebAuthProvider.login(account)
            .withAudience("TODO")
            .withScheme("TODO")
            .withScope("openid profile email offline_access")
            // Launch the authentication passing the callback where the results will be received
            .start(this.applicationContext, object : Callback<Credentials, AuthenticationException> {
                // Called when there is an authentication failure
                override fun onFailure(exception: AuthenticationException) {
                    // Something went wrong!
                }

                // Called when authentication completed successfully
                override fun onSuccess(credentials: Credentials) {
                    // Get the access token from the credentials object.
                    // This can be used to call APIs
                    val accessToken = credentials.accessToken
                }
            })
    }
}

The loginWithBrowser method was copied from the Auth0 quick start.

Additional context

I suspect the issue is in AuthenticationActivity or the Google library which Auth0 is using.

Auth0.Android version

2.10.1

Android version(s)

7.0 and 13.0

@jbsohn jbsohn added the bug This points to a verified bug in the code label Sep 13, 2023
@poovamraj
Copy link
Contributor

Hi @jbsohn thanks for raising this. Let me analyze this and get back to you.

@poovamraj
Copy link
Contributor

Hey @jbsohn Thanks a lot for the great bug report. It helped us find the memory leak and fix it here - #690. Do have a look at it and let us know your feedback. It would be great if you can fork it and test it as well. We will close this issue now but let us continue the conversation in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This points to a verified bug in the code
Projects
None yet
Development

No branches or pull requests

2 participants