Skip to content

Conversation

@kamenkremen
Copy link
Contributor

@kamenkremen kamenkremen commented Dec 18, 2025

For older Tarantool versions vshard uses func.call to execute functions.

If such a function raises an error during an uncommitted transaction, 'Transaction is active...' error is going to be raised, which will mask the original error.

This patch fixes that bug by checking the function call result. If the function returns an error and a transaction is still active, vshard now explicitly rolls back the transaction.

Fixes #614
Fixes #630

NO_DOC=bugfix

Copy link
Collaborator

@Serpentian Serpentian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! I'm glad, you've figured out the reason 🎉

P.S. And please, don't forget to rebase)

local err_msg = tostring(err)
t.assert_str_contains(err_msg, 'test_error')
t.assert_not_str_contains(err_msg, 'Transaction is active')
end)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cluster should be in the same state, as it was before test start, so, please, drop the func at the end:

box.schema.func.drop('test_fail')

We should also drop the variables from _G at the end

test_group.test_error_msg_is_preserved = function(g)
g.replica_1_a:exec(function()
local vshard = require('vshard')
local t = require('luatest')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need neither vshard nor luatest, they're already defined in the https://github.com/tarantool/vshard/blob/master/test/instances/storage.lua and can be accessed via ivshard and ilt accordingly

test_alerts_for_non_vshard_config_template(g, non_config_replica)
end

test_group.test_error_msg_is_preserved = function(g)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure, that plain function, defined in the _G (and not defined in the box.schema.func) is also not affected by this problem (it always returns the original error, not Transaction is active...

P.S. You can use "templates" in order avoid code duplication, e.g:

failed_calls_affect_priority_template(vconsts.FAILOVER_DOWN_SEQUENTIAL_FAIL)
failed_calls_affect_priority_template(1)

instance_name = 'named_replica'
}
})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the commit msg is a little bit misleading, I didn't manage to understand the problem from it:

For older Tarantool versions vshard uses func.call to execute functions.

Nah, we use custom local_call function for older versions, which uses func.call for functions defined in the box.schema.func and net.box.self.call for everything else


So, at the end only box.schema.func are affected by this problem?

-- its original error will be masked by the 'Transaction is active...'
-- error, so we check function result manually and rollback the transaction
-- in case of an error.
local count, results = (function(...)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is really difficult to read, can we just copy-paste the handle_eval_result and use it as follows:

https://github.com/tarantool/tarantool/blob/510e0b0b07f4fcaddee8ac8dd889f55c2b86c02a/src/box/lua/net_box.lua#L1412

@Serpentian Serpentian assigned kamenkremen and unassigned Serpentian Dec 22, 2025
@kamenkremen kamenkremen force-pushed the gh-614 branch 2 times, most recently from bc5d7d5 to 3b9b8c7 Compare December 23, 2025 19:34
For older Tarantool versions vshard uses func.call to execute functions
registered in schema.

If such a function raises an error during an uncommitted transaction,
'Transaction is active...' error is going to be raised, which will mask
the original error.

This patch fixes that bug by checking the function call result. If the
function returns an error and a transaction is still active, vshard now
explicitly rolls back the transaction.

Additionally, this patch fixes inconsistent return types. Previously,
functions registered in the schema returned raw cdata (such as tuples),
while other functions returned data converted via msgpack. This patch
ensures consistency by performing a msgpack conversion for registered
functions as well.

Fixes tarantool#614
Fixes tarantool#630

NO_DOC=bugfix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants