Permalink
Browse files

db, bugfix: deadlock when multi fiber access in db.trans.

  • Loading branch information...
xicilion committed Dec 6, 2017
1 parent 4394b5e commit 68a1cb5bc464af13be1a54d70d2b7750bf02c2a7
Showing with 17 additions and 2 deletions.
  1. +3 −0 fibjs/src/db/sql/trans.h
  2. +14 −2 test/db_test.js
View
@@ -10,7 +10,10 @@ inline result_t _trans(DbConnection_base* db, v8::Local<v8::Function> func)
if (hr < 0)
return hr;
db->leave();
v8::Local<v8::Value> result = func->Call(db->wrap(), 0, NULL);
db->enter();
if (result.IsEmpty()) {
db->ac_rollback();
return CALL_E_JAVASCRIPT;
View
@@ -186,14 +186,26 @@ describe("db", () => {
assert.equal(rs[0].t2, "test101.2");
});
it("auto commit with fiber", () => {
conn.trans(function () {
assert.equal(this, conn);
coroutine.parallel(() => {
this.execute("update test set t2='test101.2.1' where t1=101");
});
});
var rs = conn.execute("select * from test where t1=101");
assert.equal(rs[0].t2, "test101.2.1");
});
it("auto rollback", () => {
conn.trans(function () {
this.execute("update test set t2='test101.3' where t1=101");
return false;
});
var rs = conn.execute("select * from test where t1=101");
assert.equal(rs[0].t2, "test101.2");
assert.equal(rs[0].t2, "test101.2.1");
});
it("rollback when throw", () => {
@@ -205,7 +217,7 @@ describe("db", () => {
});
var rs = conn.execute("select * from test where t1=101");
assert.equal(rs[0].t2, "test101.2");
assert.equal(rs[0].t2, "test101.2.1");
});
});
});

0 comments on commit 68a1cb5

Please sign in to comment.