diff --git a/src/box/memtx_tx.c b/src/box/memtx_tx.c
index 92aab79347b409007e913ba7a5e8515b5004a99c..df60b9e7109d50454fe65026e37efd90e365503a 100644
--- a/src/box/memtx_tx.c
+++ b/src/box/memtx_tx.c
@@ -1431,9 +1431,11 @@ memtx_tx_history_add_insert_stmt(struct txn_stmt *stmt,
 		replaced_story = memtx_tx_story_get(replaced);
 		memtx_tx_story_link_top_light(add_story, replaced_story, 0);
 	} else {
-		memtx_tx_handle_gap_write(stmt->txn, space,
-					  add_story, new_tuple,
-					  direct_successor[0], 0);
+		rc = memtx_tx_handle_gap_write(stmt->txn, space,
+					       add_story, new_tuple,
+					       direct_successor[0], 0);
+		if (rc != 0)
+			goto fail;
 	}
 
 	/* Purge found conflicts. */
@@ -1448,9 +1450,11 @@ memtx_tx_history_add_insert_stmt(struct txn_stmt *stmt,
 		replaced_story->link[0].in_index = NULL;
 	for (uint32_t i = 1; i < space->index_count; i++) {
 		if (directly_replaced[i] == NULL) {
-			memtx_tx_handle_gap_write(stmt->txn, space,
-						  add_story, new_tuple,
-						  direct_successor[i], i);
+			rc = memtx_tx_handle_gap_write(stmt->txn, space,
+						       add_story, new_tuple,
+						       direct_successor[i], i);
+			if (rc != 0)
+				goto fail;
 			continue;
 		}
 		assert(directly_replaced[i]->is_dirty);