Fixed
Status Update
Comments
ia...@gmail.com <ia...@gmail.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit e36c65f67e49ddbfa0080542295f4a4850ae17da
Author: Sumir Kataria <sumir@google.com>
Date: Tue Aug 07 13:04:03 2018
Enforce ConstraintTracker#setState is on the main thread.
- setState now asserts that we are on the main thread
- Moved assert*Thread methods into their own utils
- Annotated several tests manually calling onBroadcastReceive
as @UiThreadTest as our broadcast receivers only operate on
the main thread (they use the default registerReceiver
method)
- NetworkCallbacks are invoked on non-main threads by default;
in this case, we re-post them to the main thread
This is part of the solution to a concurrency exception in
ConstraintTracker.
Bug: 112272753
Test: Updated and ran tests
Change-Id: I7011e5993b814f4fcafe861e283a827cd1edee12
M work/workmanager/build.gradle
M work/workmanager/src/androidTest/java/androidx/work/impl/constraints/trackers/BatteryChargingTrackerTest.java
M work/workmanager/src/androidTest/java/androidx/work/impl/constraints/trackers/BatteryNotLowTrackerTest.java
M work/workmanager/src/androidTest/java/androidx/work/impl/constraints/trackers/ConstraintTrackerTest.java
M work/workmanager/src/androidTest/java/androidx/work/impl/constraints/trackers/StorageNotLowTrackerTest.java
M work/workmanager/src/androidTest/java/androidx/work/impl/workers/ConstraintTrackingWorkerTest.java
M work/workmanager/src/main/java/androidx/work/impl/WorkManagerImpl.java
M work/workmanager/src/main/java/androidx/work/impl/background/systemalarm/SystemAlarmDispatcher.java
M work/workmanager/src/main/java/androidx/work/impl/constraints/trackers/ConstraintTracker.java
M work/workmanager/src/main/java/androidx/work/impl/constraints/trackers/NetworkStateTracker.java
A work/workmanager/src/main/java/androidx/work/impl/utils/ThreadUtils.java
https://android-review.googlesource.com/727429
https://goto.google.com/android-sha1/e36c65f67e49ddbfa0080542295f4a4850ae17da
Branch: androidx-master-dev
commit e36c65f67e49ddbfa0080542295f4a4850ae17da
Author: Sumir Kataria <sumir@google.com>
Date: Tue Aug 07 13:04:03 2018
Enforce ConstraintTracker#setState is on the main thread.
- setState now asserts that we are on the main thread
- Moved assert*Thread methods into their own utils
- Annotated several tests manually calling onBroadcastReceive
as @UiThreadTest as our broadcast receivers only operate on
the main thread (they use the default registerReceiver
method)
- NetworkCallbacks are invoked on non-main threads by default;
in this case, we re-post them to the main thread
This is part of the solution to a concurrency exception in
ConstraintTracker.
Bug: 112272753
Test: Updated and ran tests
Change-Id: I7011e5993b814f4fcafe861e283a827cd1edee12
M work/workmanager/build.gradle
M work/workmanager/src/androidTest/java/androidx/work/impl/constraints/trackers/BatteryChargingTrackerTest.java
M work/workmanager/src/androidTest/java/androidx/work/impl/constraints/trackers/BatteryNotLowTrackerTest.java
M work/workmanager/src/androidTest/java/androidx/work/impl/constraints/trackers/ConstraintTrackerTest.java
M work/workmanager/src/androidTest/java/androidx/work/impl/constraints/trackers/StorageNotLowTrackerTest.java
M work/workmanager/src/androidTest/java/androidx/work/impl/workers/ConstraintTrackingWorkerTest.java
M work/workmanager/src/main/java/androidx/work/impl/WorkManagerImpl.java
M work/workmanager/src/main/java/androidx/work/impl/background/systemalarm/SystemAlarmDispatcher.java
M work/workmanager/src/main/java/androidx/work/impl/constraints/trackers/ConstraintTracker.java
M work/workmanager/src/main/java/androidx/work/impl/constraints/trackers/NetworkStateTracker.java
A work/workmanager/src/main/java/androidx/work/impl/utils/ThreadUtils.java
yb...@google.com <yb...@google.com>
yb...@google.com <yb...@google.com> #3
yb...@google.com <yb...@google.com> #4
back to p2 since the most pressing part is fixed.
ia...@gmail.com <ia...@gmail.com> #5
As I understand it, any non-Room suspending method in the middle of a transaction will still break since you might resume the coroutine on a different thread?
I think I'd personally really like an extension method of:
fun RoomDatabase.transaction(body: suspend () -> Unit)
that replaces / obsoletes runInTransaction and would be safe to do both Room suspend methods and other, non-Room suspend methods, always returning to the correct thread for the transaction.
I think I'd personally really like an extension method of:
fun RoomDatabase.transaction(body: suspend () -> Unit)
that replaces / obsoletes runInTransaction and would be safe to do both Room suspend methods and other, non-Room suspend methods, always returning to the correct thread for the transaction.
yb...@google.com <yb...@google.com> #6
yea the issue w/ suspending room version is that we need to make sure we can carry over the transaction information so that it can go to the right thread and only it (not some other parallel task).
This is why we need a proper transaction abstraction to safely do these jumps (or at least thats what i thnk we'll need, maybe not)
This is why we need a proper transaction abstraction to safely do these jumps (or at least thats what i thnk we'll need, maybe not)
ap...@google.com <ap...@google.com> #7
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 69961b4ef143d82f50c3a7fd3969826d51a0ee25
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Thu Jan 31 12:57:58 2019
Room Suspending Transaction
Create an API for performing database transaction with coroutines. When
starting a transaction coroutine a thread of the database query executor
is hold for performing all database operations within the coroutine. It
is recommended that all DAO functions invoked are also suspend
functions. In the case they are blocking DAO methods, then invoking
those on a different context other than the transaction context will
throw an exception, preventing possible deadlocks.
Bug: 120854786
Test: ./gradlew room:room-compiler:test
room:integration-tests:room-testapp-kotlin:cC
room:integration-tests:room-testapp:cC
Change-Id: I30f76db29a3882968f43e1dd1c1038b5afd7f299
M room/compiler/src/main/kotlin/androidx/room/solver/prepared/binder/InstantPreparedQueryResultBinder.kt
M room/compiler/src/main/kotlin/androidx/room/solver/query/result/InstantQueryResultBinder.kt
M room/compiler/src/main/kotlin/androidx/room/solver/shortcut/binder/InstantDeleteOrUpdateMethodBinder.kt
M room/compiler/src/main/kotlin/androidx/room/solver/shortcut/binder/InstantInsertMethodBinder.kt
M room/compiler/src/test/data/daoWriter/output/ComplexDao.java
M room/compiler/src/test/data/daoWriter/output/DeletionDao.java
M room/compiler/src/test/data/daoWriter/output/UpdateDao.java
M room/compiler/src/test/data/daoWriter/output/WriterDao.java
M room/coroutines/api/2.1.0-alpha05.txt
M room/coroutines/api/current.txt
M room/coroutines/build.gradle
M room/coroutines/src/main/java/androidx/room/CoroutinesRoom.kt
A room/coroutines/src/main/java/androidx/room/RoomDatabase.kt
M room/integration-tests/kotlintestapp/build.gradle
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/SuspendingQueryTest.kt
M room/runtime/api/restricted_2.1.0-alpha05.txt
M room/runtime/api/restricted_current.txt
M room/runtime/src/main/java/androidx/room/RoomDatabase.java
https://android-review.googlesource.com/891674
https://goto.google.com/android-sha1/69961b4ef143d82f50c3a7fd3969826d51a0ee25
Branch: androidx-master-dev
commit 69961b4ef143d82f50c3a7fd3969826d51a0ee25
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Thu Jan 31 12:57:58 2019
Room Suspending Transaction
Create an API for performing database transaction with coroutines. When
starting a transaction coroutine a thread of the database query executor
is hold for performing all database operations within the coroutine. It
is recommended that all DAO functions invoked are also suspend
functions. In the case they are blocking DAO methods, then invoking
those on a different context other than the transaction context will
throw an exception, preventing possible deadlocks.
Bug: 120854786
Test: ./gradlew room:room-compiler:test
room:integration-tests:room-testapp-kotlin:cC
room:integration-tests:room-testapp:cC
Change-Id: I30f76db29a3882968f43e1dd1c1038b5afd7f299
M room/compiler/src/main/kotlin/androidx/room/solver/prepared/binder/InstantPreparedQueryResultBinder.kt
M room/compiler/src/main/kotlin/androidx/room/solver/query/result/InstantQueryResultBinder.kt
M room/compiler/src/main/kotlin/androidx/room/solver/shortcut/binder/InstantDeleteOrUpdateMethodBinder.kt
M room/compiler/src/main/kotlin/androidx/room/solver/shortcut/binder/InstantInsertMethodBinder.kt
M room/compiler/src/test/data/daoWriter/output/ComplexDao.java
M room/compiler/src/test/data/daoWriter/output/DeletionDao.java
M room/compiler/src/test/data/daoWriter/output/UpdateDao.java
M room/compiler/src/test/data/daoWriter/output/WriterDao.java
M room/coroutines/api/2.1.0-alpha05.txt
M room/coroutines/api/current.txt
M room/coroutines/build.gradle
M room/coroutines/src/main/java/androidx/room/CoroutinesRoom.kt
A room/coroutines/src/main/java/androidx/room/RoomDatabase.kt
M room/integration-tests/kotlintestapp/build.gradle
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/SuspendingQueryTest.kt
M room/runtime/api/restricted_2.1.0-alpha05.txt
M room/runtime/api/restricted_current.txt
M room/runtime/src/main/java/androidx/room/RoomDatabase.java
ap...@google.com <ap...@google.com> #8
Project: platform/frameworks/support
Branch: androidx-master-dev
commit f0f9ed8db13fbeb028391af00b626e19a0f2746e
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Mon Feb 11 14:35:55 2019
Deprecate RoomDatabase transaction methods.
Deprecate beginTransaction, setTransactionSuccessful and endTransaction,
in favor of runInTransaction. Deprecating these methods discourage
users from using them within coroutines.
Bug: 120854786
Test: ./gradlew room:room-compiler:test
room:integration-tests:room-testapp-kotlin:cC
room:integration-tests:room-testapp:cC
Change-Id: Idc1bb04555fdba78eb1142b3ba461b87e6b06a69
M room/compiler/src/main/kotlin/androidx/room/writer/ClassWriter.kt
M room/compiler/src/test/data/daoWriter/output/ComplexDao.java
M room/compiler/src/test/data/daoWriter/output/DeletionDao.java
M room/compiler/src/test/data/daoWriter/output/UpdateDao.java
M room/compiler/src/test/data/daoWriter/output/WriterDao.java
M room/compiler/src/test/data/databasewriter/output/ComplexDatabase.java
M room/compiler/src/test/kotlin/androidx/room/writer/EntityCursorConverterWriterTest.kt
M room/coroutines/src/main/java/androidx/room/RoomDatabase.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/migration/MigrationKotlinTest.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/SuspendingQueryTest.kt
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/migration/FtsMigrationTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/migration/MigrationTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/paging/DataSourceFactoryTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/ForeignKeyTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/MultiInstanceInvalidationTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/QueryTransactionTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/RxJava2Test.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/RxJava2WithInstantTaskExecutorTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/WriteAheadLoggingTest.java
M room/runtime/api/2.1.0-alpha05.txt
M room/runtime/api/current.txt
M room/runtime/src/main/java/androidx/room/RoomDatabase.java
M room/runtime/src/main/java/androidx/room/paging/LimitOffsetDataSource.java
https://android-review.googlesource.com/900916
https://goto.google.com/android-sha1/f0f9ed8db13fbeb028391af00b626e19a0f2746e
Branch: androidx-master-dev
commit f0f9ed8db13fbeb028391af00b626e19a0f2746e
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Mon Feb 11 14:35:55 2019
Deprecate RoomDatabase transaction methods.
Deprecate beginTransaction, setTransactionSuccessful and endTransaction,
in favor of runInTransaction. Deprecating these methods discourage
users from using them within coroutines.
Bug: 120854786
Test: ./gradlew room:room-compiler:test
room:integration-tests:room-testapp-kotlin:cC
room:integration-tests:room-testapp:cC
Change-Id: Idc1bb04555fdba78eb1142b3ba461b87e6b06a69
M room/compiler/src/main/kotlin/androidx/room/writer/ClassWriter.kt
M room/compiler/src/test/data/daoWriter/output/ComplexDao.java
M room/compiler/src/test/data/daoWriter/output/DeletionDao.java
M room/compiler/src/test/data/daoWriter/output/UpdateDao.java
M room/compiler/src/test/data/daoWriter/output/WriterDao.java
M room/compiler/src/test/data/databasewriter/output/ComplexDatabase.java
M room/compiler/src/test/kotlin/androidx/room/writer/EntityCursorConverterWriterTest.kt
M room/coroutines/src/main/java/androidx/room/RoomDatabase.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/migration/MigrationKotlinTest.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/SuspendingQueryTest.kt
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/migration/FtsMigrationTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/migration/MigrationTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/paging/DataSourceFactoryTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/ForeignKeyTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/MultiInstanceInvalidationTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/QueryTransactionTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/RxJava2Test.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/RxJava2WithInstantTaskExecutorTest.java
M room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/WriteAheadLoggingTest.java
M room/runtime/api/2.1.0-alpha05.txt
M room/runtime/api/current.txt
M room/runtime/src/main/java/androidx/room/RoomDatabase.java
M room/runtime/src/main/java/androidx/room/paging/LimitOffsetDataSource.java
Description
withContext(Dispatchers.Default) {
db.beginTransaction()
db.insert(data) // DAO suspend function
db.update(anotherData) // DAO suspend function
db.setTransactionSuccessful()
db.endTransaction()
}
This can deadlock because transaction are exclusive and are ThreadLocal, meaning once a transaction is started in a thread form the default dispatcher, another coroutine dispatcher thread will get blocked even if we are within the same coroutine.