Skip to content

Add shutdown hook function for lua plugin#13045

Merged
shukitchan merged 9 commits intoapache:masterfrom
shukitchan:luashutdown
Apr 16, 2026
Merged

Add shutdown hook function for lua plugin#13045
shukitchan merged 9 commits intoapache:masterfrom
shukitchan:luashutdown

Conversation

@shukitchan
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_down and wires it to TS_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.

Comment thread plugins/lua/ts_lua_common.h Outdated
Comment thread plugins/lua/ts_lua.cc
Comment thread tests/gold_tests/pluginTest/lua/lua_global_shutdown.test.py
Comment thread tests/gold_tests/pluginTest/lua/lua_global_shutdown.test.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread plugins/lua/ts_lua.cc
Comment thread tests/gold_tests/pluginTest/lua/lua_global_shutdown.test.py
Comment thread tests/gold_tests/pluginTest/lua/lua_global_shutdown.test.py
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread plugins/lua/ts_lua.cc Outdated
Comment thread plugins/lua/ts_lua.cc Outdated
shukitchan and others added 2 commits March 31, 2026 17:19
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@shukitchan shukitchan marked this pull request as ready for review April 1, 2026 15:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread plugins/lua/ts_lua.cc
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);
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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;
}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the existing ts_lua_reload_module grabs a lock like this in a similar way already?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

correct

@bneradt bneradt modified the milestones: 10.2.0, 11.0.0 Apr 15, 2026
@shukitchan shukitchan merged commit cb2b336 into apache:master Apr 16, 2026
19 checks passed
@github-project-automation github-project-automation bot moved this to For v10.2.0 in ATS v10.2.x Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: For v10.2.0

Development

Successfully merging this pull request may close these issues.

3 participants