From 53852b1238c341bd009ca41854ec227d301564ef Mon Sep 17 00:00:00 2001
From: Konstantin Osipov <kostja@tarantool.org>
Date: Wed, 18 Feb 2015 19:45:47 +0300
Subject: [PATCH] gh-728: segfault on parallel lua call execution

Turn off jit for box.commit(), which yields.
A test case is missing since I failed to crash the
interpreter from the test suite (apparently it needs
a more complicated background logic than one can do in
a test case).
---
 src/box/lua/call.cc    | 18 ++++++++++++++++++
 src/box/lua/schema.lua | 12 +++---------
 src/box/txn.cc         | 21 ---------------------
 src/box/txn.h          |  7 -------
 test/big/big.lua       |  2 +-
 test/box/access.result |  3 +--
 6 files changed, 23 insertions(+), 40 deletions(-)

diff --git a/src/box/lua/call.cc b/src/box/lua/call.cc
index b4a1ab2845..2fb66a5af8 100644
--- a/src/box/lua/call.cc
+++ b/src/box/lua/call.cc
@@ -329,6 +329,23 @@ lbox_delete(lua_State *L)
 	return lua_gettop(L) - 3;
 }
 
+static int
+lbox_commit(lua_State * /* L */)
+{
+	struct txn *txn = in_txn();
+	/**
+	 * COMMIT is like BEGIN or ROLLBACK
+	 * a "transaction-initiating statement".
+	 * Do nothing if transaction is not started,
+	 * it's the same as BEGIN + COMMIT.
+	*/
+	if (txn) {
+		txn_commit(txn);
+		txn_finish(txn);
+	}
+	return 0;
+}
+
 /**
  * A helper to find a Lua function by name and put it
  * on top of the stack.
@@ -655,6 +672,7 @@ lbox_snapshot(struct lua_State *L)
 
 static const struct luaL_reg boxlib[] = {
 	{"snapshot", lbox_snapshot},
+	{"commit", lbox_commit},
 	{NULL, NULL}
 };
 
diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua
index d4dd2afb0e..410379e8b5 100644
--- a/src/box/lua/schema.lua
+++ b/src/box/lua/schema.lua
@@ -55,9 +55,6 @@ ffi.cdef[[
     int
     boxffi_txn_begin();
 
-    int
-    boxffi_txn_commit();
-
     void
     boxffi_txn_rollback();
 ]]
@@ -204,11 +201,8 @@ box.begin = function()
         box.error()
     end
 end
-box.commit = function()
-    if ffi.C.boxffi_txn_commit() == -1 then
-        box.error()
-    end
-end
+-- box.commit yields, so it's defined in call.cc
+
 box.rollback = ffi.C.boxffi_txn_rollback;
 
 box.schema.space = {}
@@ -1044,7 +1038,7 @@ end
 
 box.schema.user.passwd = function(name, new_password)
     if name == nil then
-        error('Usage: box.schema.user.passwd([user,] password)')
+        box.error(box.error.PROC_LUA, "Usage: box.schema.user.passwd([user,] password)")
     end
     if new_password == nil then
         -- change password for current user
diff --git a/src/box/txn.cc b/src/box/txn.cc
index 93dd90075e..14119838f1 100644
--- a/src/box/txn.cc
+++ b/src/box/txn.cc
@@ -328,27 +328,6 @@ boxffi_txn_begin()
 	return 0;
 }
 
-int
-boxffi_txn_commit()
-{
-	try {
-		struct txn *txn = in_txn();
-		/**
-		 * COMMIT is like BEGIN or ROLLBACK
-		 * a "transaction-initiating statement".
-		 * Do nothing if transaction is not started,
-		 * it's the same as BEGIN + COMMIT.
-		 */
-		if (txn) {
-			txn_commit(txn);
-			txn_finish(txn);
-		}
-	} catch (Exception  *e) {
-		return -1; /* pass exception through FFI */
-	}
-	return 0;
-}
-
 void
 boxffi_txn_rollback()
 {
diff --git a/src/box/txn.h b/src/box/txn.h
index 51b9f1d188..1f2122c767 100644
--- a/src/box/txn.h
+++ b/src/box/txn.h
@@ -160,13 +160,6 @@ extern "C" {
 int
 boxffi_txn_begin();
 
-/**
- * @retval 0 - success
- * @retval -1 - commit failed
- */
-int
-boxffi_txn_commit();
-
 void
 boxffi_txn_rollback();
 
diff --git a/test/big/big.lua b/test/big/big.lua
index c17a780008..717b7deaec 100644
--- a/test/big/big.lua
+++ b/test/big/big.lua
@@ -4,7 +4,7 @@ box.cfg{
     listen              = os.getenv("LISTEN"),
     slab_alloc_arena    = 0.1,
     pid_file            = "tarantool.pid",
-    rows_per_wal        = 50
+    rows_per_wal        = 500000
 }
 
 require('console').listen(os.getenv('ADMIN'))
diff --git a/test/box/access.result b/test/box/access.result
index de50fc7337..de2a8ba082 100644
--- a/test/box/access.result
+++ b/test/box/access.result
@@ -394,8 +394,7 @@ box.schema.user.passwd('invalid_user', 'some_password')
 ...
 box.schema.user.passwd()
 ---
-- error: '[string "-- schema.lua (internal file)..."]:1047: Usage: box.schema.user.passwd([user,]
-    password)'
+- error: 'Usage: box.schema.user.passwd([user,] password)'
 ...
 session.su('user1')
 ---
-- 
GitLab