diff --git a/src/box/engine_sophia.cc b/src/box/engine_sophia.cc
index 114e71c348cd8ec66cda0e3c57496bcd4e3d2c51..c5df41b195268b4490c7a42bb691ee45e224415e 100644
--- a/src/box/engine_sophia.cc
+++ b/src/box/engine_sophia.cc
@@ -205,20 +205,16 @@ SophiaFactory::keydefCheck(struct key_def *key_def)
 void
 SophiaFactory::txnFinish(struct txn *txn)
 {
-	/**
-	 * @todo: support multi-statement transactions
-	 * here when sophia supports them.
-	 */
-
-	/* single-stmt case:
-	 *
-	 * no need to unref tuple here, since it will be done by
-	 * TupleGuard in execute_replace().
-	*/
-	(void)txn;
-#if 0
-	struct txn_stmt *stmt = txn_stmt(txn);
-	if (stmt->new_tuple)
-		tuple_unref(stmt->new_tuple);
-#endif
+	/* @todo: multi-statement transactions */
+
+	/* single-stmt case */
+	if (txn->n_stmts == 1) {
+		struct txn_stmt *stmt = txn_stmt(txn);
+		if (stmt->new_tuple) {
+			/* 2 refs: iproto case */
+			/* 3 refs: lua case */
+			assert(stmt->new_tuple->refs >= 2);
+			tuple_unref(stmt->new_tuple);
+		}
+	}
 }
diff --git a/src/lua/trigger.cc b/src/lua/trigger.cc
index 6ffa2a5ed23a049ba78178ffab7a72303f561f8d..3fafdd1cc42a1ab61f483dfb33f868f3310445c7 100644
--- a/src/lua/trigger.cc
+++ b/src/lua/trigger.cc
@@ -32,7 +32,9 @@
 void
 lbox_trigger_destroy(struct trigger *trigger)
 {
-	luaL_unref(tarantool_L, LUA_REGISTRYINDEX, (intptr_t) trigger->data);
+	if (tarantool_L)
+		luaL_unref(tarantool_L,
+			LUA_REGISTRYINDEX, (intptr_t) trigger->data);
 	free(trigger);
 }
 
diff --git a/test/app/trigger_atexit.result b/test/app/trigger_atexit.result
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/test/app/trigger_atexit.test.lua b/test/app/trigger_atexit.test.lua
new file mode 100755
index 0000000000000000000000000000000000000000..1e85558d9effec3aea8b4ae2fcb4bf96ea5a4439
--- /dev/null
+++ b/test/app/trigger_atexit.test.lua
@@ -0,0 +1,35 @@
+#!/usr/bin/env tarantool
+-- vim: set ft=lua :
+
+-- see https://github.com/tarantool/tarantool/issues/583
+
+tap = require 'tap'
+fio = require 'fio'
+log = require 'log'
+
+tempdir = fio.tempdir()
+
+box.cfg {
+    wal_dir = tempdir,
+    snap_dir = tempdir,
+    sophia_dir = tempdir,
+    logger      = fio.pathjoin(tempdir, 'tarantool.log')
+}
+
+local function test_replace(old_tuple, new_tuple)
+
+end
+
+
+box.schema.create_space('abc')
+box.space.abc:create_index('pk', { type = 'tree' })
+box.space.abc:on_replace(test_replace)
+
+
+cleanup_list = fio.glob(fio.pathjoin(tempdir), '*')
+for _, file in pairs(cleanup_list) do
+    fio.unlink(file)
+end
+fio.rmdir(tempdir)
+os.exit(0)
+
diff --git a/test/box/bsdsocket.skipcond b/test/box/bsdsocket.skipcond
new file mode 100644
index 0000000000000000000000000000000000000000..80f2117b5fbfdcfc432b446f61ad06fb91eac5b6
--- /dev/null
+++ b/test/box/bsdsocket.skipcond
@@ -0,0 +1,22 @@
+
+# vim: set ft=python :
+import re
+import os.path
+import socket
+import os
+
+test_path = '/tmp/tarantool-test-socket'
+
+if os.path.exists(test_path):
+    os.remove(test_path)
+
+s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+try:
+    s.bind(test_path)
+except:
+    self.skip = 1
+
+s.close()
+
+if os.path.exists(test_path):
+    os.remove(test_path)