Set isInTransaction to false even if close throws
If a transaction wrapper's closer throws (such as flushBatchedUpdates in ReactDefaultBatchingStrategy) then we still want to properly deinitialize the transaction by setting isInTransaction to false. Without this, we can't reuse the transaction object (in this case, all future batched updates would fail because nested transactions aren't allowed).
Ben Alpert committed
Feb 4, 2014 at 10:50 UTC
17f602f9245e7dc38b2dc1528f2fe9f5324b9b8e
2 files changed
+14
-10
src/utils/Transaction.js
+13
-10
@@ -161,19 +161,22 @@ var Mixin = {
161
} finally {
162
var memberEnd = Date.now();
163
this.methodInvocationTime += (memberEnd - memberStart);
164
- if (errorThrown) {
165
- // If `method` throws, prefer to show that stack trace over any thrown
166
- // by invoking `closeAll`.
167
- try {
164
+ try {
165
+ if (errorThrown) {
166
+ // If `method` throws, prefer to show that stack trace over any thrown
167
+ // by invoking `closeAll`.
168
+ try {
169
+ this.closeAll(0);
170
+ } catch (err) {
171
+ }
172
+ } else {
173
+ // Since `method` didn't throw, we don't want to silence the exception
174
+ // here.
175
this.closeAll(0);
169
- } catch (err) {
176
}
171
- } else {
172
- // Since `method` didn't throw, we don't want to silence the exception
173
- // here.
174
- this.closeAll(0);
177
+ } finally {
178
+ this._isInTransaction = false;
179
}
176
- this._isInTransaction = false;
180
}
181
return ret;
182
},
src/utils/__tests__/Transaction-test.js
+1
@@ -243,6 +243,7 @@ describe('Transaction', function() {
243
expect(function() {
244
transaction.perform(function() {});
245
}).toThrow(exceptionMsg);
246
+ expect(transaction.isInTransaction()).toBe(false);
247
});
248
249
it('should allow nesting of transactions', function() {