Fixed
Status Update
Comments
ku...@google.com <ku...@google.com>
ku...@google.com <ku...@google.com> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
ku...@google.com <ku...@google.com> #3
yea i'll take it.
ku...@google.com <ku...@google.com> #4
Thanks for the detailed analysis. This may not be an issue anymore since we've started using Main.immediate there but I' not sure; I'll try to create a test case.
sm...@gmail.com <sm...@gmail.com> #5
just emitting same live data reproduces the issue.
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
sm...@gmail.com <sm...@gmail.com> #6
With 2.2.0-alpha04 (that use Main.immediate), the issue seems to be still there (I tested it by calling emitSource() twice, like your test case)
sm...@gmail.com <sm...@gmail.com> #7
yea sorry immediate does not fix it.
I actually have a WIP fix for it:
https://android-review.googlesource.com/c/platform/frameworks/support/+/1112186
if your case is the one i found (emitting same LiveData multiple times, as shown in #5) you can work around it by adding a dummy transformation.
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData.map {it })
emitSource(subLiveData.map {it} )
}
I actually have a WIP fix for it:
if your case is the one i found (emitting same LiveData multiple times, as shown in #5) you can work around it by adding a dummy transformation.
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData.map {it })
emitSource(subLiveData.map {it} )
}
il...@google.com <il...@google.com> #8
Project: platform/frameworks/support
Branch: androidx-master-dev
commit af12e75e6b4110f48e44ca121466943909de8f06
Author: Yigit Boyar <yboyar@google.com>
Date: Tue Sep 03 12:58:11 2019
Fix coroutine livedata race condition
This CL fixes a bug in liveData builder where emitting same
LiveData source twice would make it crash because the second
emission registry could possibly happen before first one is
removed as source.
We fix it by using a suspending dispose function. It does feel
a bit hacky but we cannot make DisposableHandle.dispose async
and we do not want to block there. This does not mean that there
is a problem if developer disposes it manually since our emit
functions take care of making sure it disposes (and there is
no other way to add source to the underlying MediatorLiveData)
Bug: 140249349
Test: BuildLiveDataTest#raceTest_*
Change-Id: I0b464c242a583da4669af195cf2504e2adc4de40
M lifecycle/lifecycle-livedata-ktx/api/2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/current.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_current.txt
M lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/CoroutineLiveData.kt
M lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/BuildLiveDataTest.kt
https://android-review.googlesource.com/1112186
https://goto.google.com/android-sha1/af12e75e6b4110f48e44ca121466943909de8f06
Branch: androidx-master-dev
commit af12e75e6b4110f48e44ca121466943909de8f06
Author: Yigit Boyar <yboyar@google.com>
Date: Tue Sep 03 12:58:11 2019
Fix coroutine livedata race condition
This CL fixes a bug in liveData builder where emitting same
LiveData source twice would make it crash because the second
emission registry could possibly happen before first one is
removed as source.
We fix it by using a suspending dispose function. It does feel
a bit hacky but we cannot make DisposableHandle.dispose async
and we do not want to block there. This does not mean that there
is a problem if developer disposes it manually since our emit
functions take care of making sure it disposes (and there is
no other way to add source to the underlying MediatorLiveData)
Bug: 140249349
Test: BuildLiveDataTest#raceTest_*
Change-Id: I0b464c242a583da4669af195cf2504e2adc4de40
M lifecycle/lifecycle-livedata-ktx/api/2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/current.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_current.txt
M lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/CoroutineLiveData.kt
M lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/BuildLiveDataTest.kt
af...@gmail.com <af...@gmail.com> #9
I just wound up using the following as a work around:
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
dialogView = LayoutInflater.from(context).inflate(R.layout.fragment_add_user, null)
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
dialogView = LayoutInflater.from(context).inflate(R.layout.fragment_add_user, null)
jp...@gmail.com <jp...@gmail.com> #10
I uncovered this issue as well. I am working on migrating my app to use androidx fragments instead of framework. This includes migrating custom DialogFragments. Previously I was using LayoutInflater.from(context) also; I guess that's the only way to do it via framework fragments, maybe there's no "getLayoutInflater" on the fragment there.
Do you need any further samples to investigate?
Do you need any further samples to investigate?
il...@google.com <il...@google.com>
an...@google.com <an...@google.com> #11
ap...@google.com <ap...@google.com> #12
Project: platform/frameworks/support
Branch: androidx-master-dev
commit cd5549fdd847601c65d3a0e6f72a7de83c61154c
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Mar 09 13:00:19 2020
Allow calling getLayoutInflater in onCreateDialog
Calling getLayoutInflater in a custom DialogFragment's overridden
onCreateDialog method causes a StackOverflowError because
DialogFragment's onGetLayoutInflater relied on calling onCreateDialog.
In onCreateDialog, we should return the layout inflater from the
Fragment onGetLayoutInflater instead, which has no idea about the
context or theme of the Dialog. The layout inflater returned in
onCreateView will remain the same, but the two will be different.
This also fixes an issue where FragmentContainerView and the fragment
tag cannot inflate fragments within a DialogFragment. The inflated
fragments are properly added to the DialogFragment's
childFragmentManager.
Test: Added DialogFragmentInflatedChildTest test
Bug: 117894767
RelNote: "Fixed a bug in DialogFragment that caused a StackOverflowError
when calling getLayoutInflater from within onCreateDialog."
Change-Id: Ib55b53de9ccd5ccb69111d519fd7ec02fbf9726e
M fragment/fragment/build.gradle
M fragment/fragment/src/androidTest/AndroidManifest.xml
A fragment/fragment/src/androidTest/java/androidx/fragment/app/DialogFragmentInflatedChildTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/DialogFragment.java
https://android-review.googlesource.com/1253912
Branch: androidx-master-dev
commit cd5549fdd847601c65d3a0e6f72a7de83c61154c
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Mar 09 13:00:19 2020
Allow calling getLayoutInflater in onCreateDialog
Calling getLayoutInflater in a custom DialogFragment's overridden
onCreateDialog method causes a StackOverflowError because
DialogFragment's onGetLayoutInflater relied on calling onCreateDialog.
In onCreateDialog, we should return the layout inflater from the
Fragment onGetLayoutInflater instead, which has no idea about the
context or theme of the Dialog. The layout inflater returned in
onCreateView will remain the same, but the two will be different.
This also fixes an issue where FragmentContainerView and the fragment
tag cannot inflate fragments within a DialogFragment. The inflated
fragments are properly added to the DialogFragment's
childFragmentManager.
Test: Added DialogFragmentInflatedChildTest test
Bug: 117894767
RelNote: "Fixed a bug in DialogFragment that caused a StackOverflowError
when calling getLayoutInflater from within onCreateDialog."
Change-Id: Ib55b53de9ccd5ccb69111d519fd7ec02fbf9726e
M fragment/fragment/build.gradle
M fragment/fragment/src/androidTest/AndroidManifest.xml
A fragment/fragment/src/androidTest/java/androidx/fragment/app/DialogFragmentInflatedChildTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/DialogFragment.java
jb...@google.com <jb...@google.com> #13
This has been fixed internally and will be available in both the Fragment 1.2.3 release and 1.3.0-alpha02 release.
Description
Please describe the problem in detail. Be sure to include:
- Steps to reproduce the problem (including sample code if appropriate).
Subclass androidx.fragment.app.DialogFragment and in onCreateDialog get an instance of the layout inflater using getLayoutInflater.
compileSdkVersion 28
minSdkVersion 23
targetSdkVersion 28
import android.app.AlertDialog
import android.app.Dialog
import android.os.Bundle
import androidx.fragment.app.DialogFragment
class AddUserDialogFragment : DialogFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val inflater = layoutInflater // this throws a stack overflow error
val view = inflater.inflate(R.layout.fragment_add_user, null)
return AlertDialog.Builder(activity!!)
.setTitle(R.string.some_title)
.setView(view)
.setPositiveButton(R.string.add, null)
.setNegativeButton(R.string.cancel) { dialog, which ->
}
.create()
}
}
- What happened.
The call to getLayoutInflater stack overflows
2018-10-18 06:55:31.279 20850-20850/? E/AndroidRuntime: at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1308)
at androidx.fragment.app.Fragment.getLayoutInflater(Fragment.java:1293)
at com.ase.solutions.mat.organization.adduser.AddUserDialogFragment.onCreateDialog(AddUserDialogFragment.kt:26)
at androidx.fragment.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:330)
at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1308)
at androidx.fragment.app.Fragment.getLayoutInflater(Fragment.java:1293)
at com.ase.solutions.mat.organization.adduser.AddUserDialogFragment.onCreateDialog(AddUserDialogFragment.kt:26)
at androidx.fragment.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:330)
at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1308)
at androidx.fragment.app.Fragment.getLayoutInflater(Fragment.java:1293)
.. further down ...
2018-10-18 06:55:31.279 20850-20850/? E/AndroidRuntime: at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1308)
at com.ase.solutions.mat.organization.adduser.AddUserDialogFragment.onCreateDialog(AddUserDialogFragment.kt:26)
at androidx.fragment.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:330)
at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1308)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
at androidx.fragment.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
- What you think the correct behavior should be.
It should return a layout inflater
Don't forget to mention which version of Android you're using, and/or which
device the problem appears on (model and Android version).
API 28
Please also run "adb bugreport" and archive the output.