Interrupt infinite lua loop #5778
Replies: 10 comments 4 replies
-
who said lua_sethook is async-signal-safe? |
Beta Was this translation helpful? Give feedback.
-
The correct solution is to always run the hook, and check a RCU variable in it, which is set by a real time signal handler. This can simply yield the current fiber, so will even work more nicely. |
Beta Was this translation helpful? Give feedback.
-
@filonenko-mikhail, I glanced over the ticket and need some time to analyze all proposals and changes. Meanwhile the similar mechanism is and already implemented in LuaVela. Even if we wouldn't be able to replace our fork with LuaVela, I wonder whether we can incorporate that machinery into our LuaJIT fork. @kostja, since I'm not that deep into Tarantool internals for now, could you please take a look on the spec and provide pros and cons you see regarding this approach for Tarantool fibers? |
Beta Was this translation helpful? Give feedback.
-
I think we have to support compiled code interruption. |
Beta Was this translation helpful? Give feedback.
-
I mean that |
Beta Was this translation helpful? Give feedback.
-
@filonenko-mikhail, could you please provide some use cases you see as a rationale for trace executing interuption? I see the comment left by Mike but I can state nothing right now regarding it. Let's investigate the problem from both sides simultaneously and return to the question in a while? |
Beta Was this translation helpful? Give feedback.
-
There are: I think we can support two semantics at runtime:
|
Beta Was this translation helpful? Give feedback.
-
I measured the impact of the hooks enabled in traces. The one liner
gives the following output (the tail of it, see the loop contents) without hooks compiled in:
and with the hooks enabled (two extra instructions in the loop):
Which means about 0.15% slowdown on such a loop - just an increment. If we put any sort of workload from box it'll be scaled down considerably. |
Beta Was this translation helpful? Give feedback.
-
Additional case is fiber introspection
|
Beta Was this translation helpful? Give feedback.
-
Regardless of how you do it, you need to consider how are you going to break the fibers in the places which never are allowed to yield/stop.
|
Beta Was this translation helpful? Give feedback.
-
related #1898 #2857
Motivation
There is case:
while true do end
tarantool
goes to infinite loop and unavailable to make a serviceShowstopper forever
Solution
Consider
tarantool
is in infinite loop.The solution is based on three features:
POSIX signal
, OS still can send signal to lua thread (and incapsulated fiber)debug.sethook
, we have access to lua fiber context from signal handler and set hookLUAJIT_ENABLE_CHECKHOOK=1
, luajit flag enables debug.sethook for compiled codeProof Of Concept
Apply patch
Open two consoles.
Run tarantool with infinite fiber
Kill with
SIGUSR2
from other consoleExpected:
Tarantool version:
any
OS version:
any
Beta Was this translation helpful? Give feedback.
All reactions