Skip to content

Commit 8ead372

Browse files
committed
Move as much work as possible out of the sqlite txn
In particular, don't do anything that could throw in the finally block, as this will mask any exception thrown within the transaction itself.
1 parent c9f213c commit 8ead372

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLitePersistence.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,35 +143,36 @@ RemoteDocumentCache getRemoteDocumentCache() {
143143

144144
@Override
145145
void runTransaction(String action, Runnable operation) {
146+
Logger.debug(TAG, "Starting transaction: %s", action);
147+
referenceDelegate.onTransactionStarted();
148+
db.beginTransaction();
146149
try {
147-
Logger.debug(TAG, "Starting transaction: %s", action);
148-
referenceDelegate.onTransactionStarted();
149-
db.beginTransaction();
150150
operation.run();
151151

152152
// Note that an exception in operation.run() will prevent this code from running.
153153
db.setTransactionSuccessful();
154154
} finally {
155155
db.endTransaction();
156-
referenceDelegate.onTransactionCommitted();
157156
}
157+
referenceDelegate.onTransactionCommitted();
158158
}
159159

160160
@Override
161161
<T> T runTransaction(String action, Supplier<T> operation) {
162+
Logger.debug(TAG, "Starting transaction: %s", action);
163+
T value = null;
164+
referenceDelegate.onTransactionStarted();
165+
db.beginTransaction();
162166
try {
163-
Logger.debug(TAG, "Starting transaction: %s", action);
164-
referenceDelegate.onTransactionStarted();
165-
db.beginTransaction();
166-
T value = operation.get();
167+
value = operation.get();
167168

168169
// Note that an exception in operation.run() will prevent this code from running.
169170
db.setTransactionSuccessful();
170-
return value;
171171
} finally {
172172
db.endTransaction();
173-
referenceDelegate.onTransactionCommitted();
174173
}
174+
referenceDelegate.onTransactionCommitted();
175+
return value;
175176
}
176177

177178
/**

0 commit comments

Comments
 (0)