From 9afd771e9aa820addc01ef17bcad5467d447c49c Mon Sep 17 00:00:00 2001 From: Walt Karas Date: Wed, 21 Dec 2022 19:15:02 +0000 Subject: [PATCH 1/2] Fix crashes at shutdown due to references to stale debug control registry. Adds reference count for references to registry. The registry is deleted only when the reference count goes to zero. --- .../api/functions/TSDebug.en.rst | 3 + .../debugging/debug-tags.en.rst | 14 ++- include/ts/ts.h | 8 ++ include/tscore/DbgCtl.h | 10 +- include/tscpp/api/Cleanup.h | 11 ++ src/traffic_server/InkAPI.cc | 10 +- src/tscore/DbgCtl.cc | 100 +++++++++++++++--- .../pluginTest/TSVConnFd/TSVConnFd.cc | 4 +- .../polite_hook_wait/polite_hook_wait.cc | 3 +- .../gold_tests/pluginTest/tsapi/test_tsapi.cc | 7 +- 10 files changed, 147 insertions(+), 23 deletions(-) diff --git a/doc/developer-guide/api/functions/TSDebug.en.rst b/doc/developer-guide/api/functions/TSDebug.en.rst index a12551001bc..9a458bfd0de 100644 --- a/doc/developer-guide/api/functions/TSDebug.en.rst +++ b/doc/developer-guide/api/functions/TSDebug.en.rst @@ -40,6 +40,7 @@ Synopsis .. type:: TSDbgCtl .. function:: void TSDbg(const TSDbgCtl * ctlptr, const char * format, ...) .. function:: const TSDbgCtl * TSDbgCtlCreate(const char * tag) +.. function:: void TSDbgCtlDestroy(const TSDbgCtl * dbg_ctl) .. function:: void TSDebug(const char * tag, const char * format, ...) .. function:: int TSIsDbgCtlSet(const TSDbgCtl * ctlptr) .. function:: int TSIsDebugTagSet(const char * tag) @@ -86,6 +87,8 @@ trafficserver.out :func:`TSDbgCtlCreate` creates a debug control, associated with the debug :arg:`tag`, and returns a const pointer to it. +:func:`TSDbgCtlDestroy` destroys a debug control, pointed to by :arg:`dbg_ctl`. + :func:`TSIsDbgCtlSet` returns non-zero if the given debug control, pointed to by :arg:`ctlptr`, is enabled. diff --git a/doc/developer-guide/debugging/debug-tags.en.rst b/doc/developer-guide/debugging/debug-tags.en.rst index 9cd45392de1..d15d4c33a23 100644 --- a/doc/developer-guide/debugging/debug-tags.en.rst +++ b/doc/developer-guide/debugging/debug-tags.en.rst @@ -32,11 +32,14 @@ traces in your plugin. In this macro: - ``...`` are variables for ``format_str`` in the standard ``printf`` style. -``void TSDbgCtlCreate (const char *tag)`` returns a (const) pointer to +``TSDbgCtlCreate (const char *tag)`` returns a (const) pointer to ``TSDbgCtl``. The ``TSDbgCtl`` control is enabled when debug output is -enabled globally by configuaration, and ``tag`` matches a configured +enabled globally by configuration, and ``tag`` matches a configured regular expression. +``TSDbgCtlDestroy (TSDbgCtl const *dbg_ctl)`` destroys a debug control +created by ``TSDbgCtlCreast()``. + The deprecated API ``void TSDebug (const char *tag, const char *format_str, ...)`` also outputs traces. In this API: @@ -81,6 +84,8 @@ Example: TSDbg(my_dbg_ctl, "Starting my-plugin at %d", the_time); ... TSDbg(my_dbg_ctl, "Later on in my-plugin"); + ... + TSDbgCtlDestroy(my_dbg_ctl); The statement ``"Starting my-plugin at