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

"java.lang.IllegalArgumentException: Service not registered" when unbinding in SessionLifecycleServiceBinderImpl #5869

Closed
francescocervone opened this issue Apr 15, 2024 · 1 comment
Assignees

Comments

@francescocervone
Copy link

francescocervone commented Apr 15, 2024

  • Android Studio version: Android Studio Iguana | 2023.2.1 Patch 1
  • Android Gradle Plugin version: 8.3.2
  • Firebase Component: Firebase Sessions
  • Component version: Firebase BoM 32.8.0

Steps to reproduce:

Not able to reproduce the issue, but we are getting dozens of crashes on a specific device of one of our customers:

  • Wind River, Armor 2, Android 7
Fatal Exception: java.lang.IllegalArgumentException: Service not registered: [obfuscated]
       at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1331)
       at android.app.ContextImpl.unbindService(ContextImpl.java:1528)
       at android.content.ContextWrapper.unbindService(ContextWrapper.java:648)
       at com.google.firebase.sessions.SessionLifecycleServiceBinderImpl.bindToService(SessionLifecycleServiceBinder.kt:65)
       at com.google.firebase.sessions.SessionLifecycleClient.bindToService(SessionLifecycleClient.java:105)
       at com.google.firebase.sessions.FirebaseSessions$1.invokeSuspend(FirebaseSessions.kt:53)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at com.google.firebase.concurrent.CustomThreadFactory.lambda$newThread$0$com-google-firebase-concurrent-CustomThreadFactory(CustomThreadFactory.java:47)
       at com.google.firebase.concurrent.CustomThreadFactory$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:1047)
       at java.lang.Thread.run(Thread.java:761)

Relevant Code:

I see that on that line, the class is trying to unbind a service that was unable to bind before:

if (!isServiceBound) {
  appContext.unbindService(serviceConnection)
  Log.i(TAG, "Session lifecycle service binding failed.")
}
@google-oss-bot
Copy link
Contributor

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@mrober mrober self-assigned this Apr 15, 2024
argzdev added a commit that referenced this issue Apr 22, 2024
Fix for #5869.

`Fatal Exception: java.lang.IllegalArgumentException: Service not
registered: [obfuscated]` happens when the context calls `unbindService`
on a service connection that has not been bounded. Either due to
`SecurityException` or the existing service cannot be found from the map
of services that has been bounded.

Simulating tests by calling `unbindService` without initially calling
`bindService` will result to the same stacktrace as with the issue:
```
java.lang.IllegalArgumentException: Service not registered: com.example.testunbinding.MainActivity$onCreate$serviceConnection$1@8988566
                                                                                                    	at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1289)
                                                                                                    	at android.app.ContextImpl.unbindService(ContextImpl.java:1511)
                                                                                                    	at android.content.ContextWrapper.unbindService(ContextWrapper.java:648)
                                                                                                    	at com.example.testunbinding.MainActivity.onCreate$lambda$0(MainActivity.kt:48)
                                                                                                    	at com.example.testunbinding.MainActivity.$r8$lambda$mcIw03Dd4PpO0vDw0ScUjxsazkw(MainActivity.kt)
                                                                                                    	at com.example.testunbinding.MainActivity$$ExternalSyntheticLambda0.onClick(D8$$SyntheticClass:0)
```

I've verified that the try-catch for `IllegalArgumentException` works.
@mrober mrober closed this as completed May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants