Add shutdown hook function for lua plugin#13045
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a Lua global plugin shutdown hook so Lua scripts can run cleanup logic when ATS exits, along with documentation and a gold test to validate the behavior.
Changes:
- Introduces a new Lua global callback
do_global_shut_downand wires it toTS_LIFECYCLE_SHUTDOWN_HOOK. - Adds a gold test + Lua script to verify the new shutdown hook is invoked.
- Documents the new Lua hook in the admin guide.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/gold_tests/pluginTest/lua/lua_global_shutdown.test.py | New gold test that exercises the Lua global shutdown hook via ATS shutdown. |
| tests/gold_tests/pluginTest/lua/global_shutdown.lua | New Lua script implementing the new global read + shutdown hooks for the test. |
| plugins/lua/ts_lua_common.h | Adds a constant for the new Lua global shutdown function name. |
| plugins/lua/ts_lua.cc | Registers a lifecycle shutdown hook and invokes the Lua shutdown function for each Lua state. |
| doc/admin-guide/plugins/lua.en.rst | Documents the new Lua shutdown hook and provides an example. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| for (int index = 0; index < conf->states; ++index) { | ||
| ts_lua_main_ctx *const main_ctx = &ts_lua_g_main_ctx_array[index]; | ||
|
|
||
| TSMutexLock(main_ctx->mutexp); |
There was a problem hiding this comment.
TS_LIFECYCLE_SHUTDOWN_HOOK is invoked from traffic_server.cc just before TSSystemState::shut_down_event_system() (i.e., other event threads may still be running). Using blocking TSMutexLock(main_ctx->mutexp) here risks stalling shutdown if any Lua state mutex is held by in-flight work. Consider using TSMutexLockTry() (and skipping/logging when the lock can't be acquired), or otherwise ensuring the hook can't block ATS shutdown.
| TSMutexLock(main_ctx->mutexp); | |
| if (TSMutexLockTry(main_ctx->mutexp) != TS_SUCCESS) { | |
| TSError("[ts_lua][%s] skipping shutdown callback for script '%s' state %d because the lua state is busy", | |
| __FUNCTION__, conf->script, index); | |
| continue; | |
| } |
There was a problem hiding this comment.
I think the existing ts_lua_reload_module grabs a lock like this in a similar way already?
No description provided.