You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by cm...@apache.org on 2026/04/08 13:27:01 UTC

(trafficserver) 01/02: Flush logs before shutdown (#13065)

This is an automated email from the ASF dual-hosted git repository.

cmcfarlen pushed a commit to branch 10.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit a137afc414e2349d359ce01c1a149bc1e26503d7
Author: Masaori Koshiba <ma...@apache.org>
AuthorDate: Wed Apr 8 07:53:41 2026 +0900

    Flush logs before shutdown (#13065)
    
    (cherry picked from commit e99a83c458d48ce1514ab7e1d73c04a1935422b9)
---
 include/proxy/logging/Log.h          |  2 ++
 src/proxy/logging/Log.cc             | 25 +++++++++++++++++++------
 src/traffic_server/traffic_server.cc |  8 ++++++++
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/include/proxy/logging/Log.h b/include/proxy/logging/Log.h
index 4cf40db096..7c76794687 100644
--- a/include/proxy/logging/Log.h
+++ b/include/proxy/logging/Log.h
@@ -172,6 +172,8 @@ public:
   static int va_error(const char *format, va_list ap);
   static int error(const char *format, ...) TS_PRINTFLIKE(1, 2);
 
+  static void flush_all_objects();
+
   // public data members
   static LogObject *error_log;
   /** The latest fully initialized LogConfig.
diff --git a/src/proxy/logging/Log.cc b/src/proxy/logging/Log.cc
index 4ac59bf679..7f8e36e11d 100644
--- a/src/proxy/logging/Log.cc
+++ b/src/proxy/logging/Log.cc
@@ -1316,6 +1316,14 @@ Log::va_error(const char *format, va_list ap)
   return ret_val;
 }
 
+void
+Log::flush_all_objects()
+{
+  if (config) {
+    config->log_object_manager.flush_all_objects();
+  }
+}
+
 /*-------------------------------------------------------------------------
   Log::preproc_thread_main
 
@@ -1334,9 +1342,6 @@ Log::preproc_thread_main(void *args)
   Log::preproc_notify[idx].lock();
 
   while (true) {
-    if (TSSystemState::is_event_system_shut_down()) {
-      return nullptr;
-    }
     LogConfig *current = static_cast<LogConfig *>(configProcessor.get(log_configid));
 
     if (likely(current)) {
@@ -1351,6 +1356,13 @@ Log::preproc_thread_main(void *args)
       configProcessor.release(log_configid, current);
     }
 
+    // Drain any remaining buffers before exiting on shutdown.
+    if (TSSystemState::is_event_system_shut_down()) {
+      // Signal flush thread to drain data we just pushed.
+      Log::flush_notify->signal();
+      return nullptr;
+    }
+
     // wait for more work; a spurious wake-up is ok since we'll just
     // check the queue and find there is nothing to do, then wait
     // again.
@@ -1375,9 +1387,6 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */)
   Log::flush_notify->lock();
 
   while (true) {
-    if (TSSystemState::is_event_system_shut_down()) {
-      return nullptr;
-    }
     fdata = static_cast<LogFlushData *>(ink_atomiclist_popall(flush_data_list));
 
     // invert the list
@@ -1469,6 +1478,10 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */)
     // check the queue and find there is nothing to do, then wait
     // again.
     //
+    if (TSSystemState::is_event_system_shut_down()) {
+      return nullptr;
+    }
+
     Log::flush_notify->wait();
   }
 
diff --git a/src/traffic_server/traffic_server.cc b/src/traffic_server/traffic_server.cc
index 43abde3066..aecbef893f 100644
--- a/src/traffic_server/traffic_server.cc
+++ b/src/traffic_server/traffic_server.cc
@@ -287,7 +287,15 @@ struct AutoStopCont : public Continuation {
       jsonrpcServer->stop_thread();
     }
 
+    // Push buffered log entries into the preproc queue before shutdown.
+    Log::flush_all_objects();
+
     TSSystemState::shut_down_event_system();
+
+    // Wake preproc threads to drain remaining log buffers before exit.
+    for (int i = 0; i < Log::preproc_threads; i++) {
+      Log::preproc_notify[i].signal();
+    }
     delete this;
     return EVENT_CONT;
   }