TS-2363: Fix assertion of "Unknown file format type!" What leading to this assertion is that LogFile object passed to flush thread has been destroyed within Log::periodic_tasks() when accessing it.
This patch introduces refcount for LogFile object to avoid been destroyed untimely. Signed-off-by: Yunkai Zhang <qiushu....@taobao.com> Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/9410b755 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/9410b755 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/9410b755 Branch: refs/heads/5.0.x Commit: 9410b755e99322fa81ed24212b0c7902cb153e47 Parents: 3421c6e Author: Yunkai Zhang <qiushu....@taobao.com> Authored: Sun Dec 22 14:29:46 2013 +0800 Committer: Yunkai Zhang <qiushu....@taobao.com> Committed: Sun Dec 22 18:01:39 2013 +0800 ---------------------------------------------------------------------- CHANGES | 2 ++ proxy/logging/Log.h | 2 +- proxy/logging/LogFile.h | 2 +- proxy/logging/LogHost.cc | 3 +-- proxy/logging/LogHost.h | 2 +- proxy/logging/LogObject.cc | 8 ++------ proxy/logging/LogObject.h | 2 +- 7 files changed, 9 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9410b755/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index d5d4fc7..eb361c0 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ -*- coding: utf-8 -*- Changes with Apache Traffic Server 4.2.0 + *) [TS-2363] Fix assertion of "Unknown file format type!". + *) [TS-2448] Fix traffic_cop and traffic_manager to obey the proxy.config.local_state_dir setting. *) [TS-2445] Fix problem with 204 responses closing POST requests http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9410b755/proxy/logging/Log.h ---------------------------------------------------------------------- diff --git a/proxy/logging/Log.h b/proxy/logging/Log.h index a646275..92c4525 100644 --- a/proxy/logging/Log.h +++ b/proxy/logging/Log.h @@ -316,7 +316,7 @@ class LogFlushData { public: LINK(LogFlushData, link); - LogFile *m_logfile; + Ptr<LogFile> m_logfile; LogBuffer *logbuffer; void *m_data; int m_len; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9410b755/proxy/logging/LogFile.h ---------------------------------------------------------------------- diff --git a/proxy/logging/LogFile.h b/proxy/logging/LogFile.h index 1995ee7..1f8c275 100644 --- a/proxy/logging/LogFile.h +++ b/proxy/logging/LogFile.h @@ -122,7 +122,7 @@ public: LogFile -------------------------------------------------------------------------*/ -class LogFile:public LogBufferSink +class LogFile:public LogBufferSink, public RefCountObj { public: LogFile(const char *name, const char *header, LogFileFormat format, uint64_t signature, http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9410b755/proxy/logging/LogHost.cc ---------------------------------------------------------------------- diff --git a/proxy/logging/LogHost.cc b/proxy/logging/LogHost.cc index c764f77..89647aa 100644 --- a/proxy/logging/LogHost.cc +++ b/proxy/logging/LogHost.cc @@ -335,7 +335,7 @@ LogHost::clear() ats_free(m_name); delete m_sock; - delete m_orphan_file; + m_orphan_file.clear(); ink_zero(m_ip); m_port = 0; @@ -344,7 +344,6 @@ LogHost::clear() m_sock = NULL; m_sock_fd = -1; m_connected = false; - m_orphan_file = NULL; } bool LogHost::authenticated() http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9410b755/proxy/logging/LogHost.h ---------------------------------------------------------------------- diff --git a/proxy/logging/LogHost.h b/proxy/logging/LogHost.h index cc7cc6d..8442656 100644 --- a/proxy/logging/LogHost.h +++ b/proxy/logging/LogHost.h @@ -87,7 +87,7 @@ private: LogSock *m_sock; int m_sock_fd; bool m_connected; - LogFile *m_orphan_file; + Ptr<LogFile> m_orphan_file; LogCollationClientSM *m_log_collation_client_sm; public: http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9410b755/proxy/logging/LogObject.cc ---------------------------------------------------------------------- diff --git a/proxy/logging/LogObject.cc b/proxy/logging/LogObject.cc index 5109469..4869448 100644 --- a/proxy/logging/LogObject.cc +++ b/proxy/logging/LogObject.cc @@ -184,7 +184,6 @@ LogObject::~LogObject() m_host_list.clear(); } } - delete m_logFile; ats_free(m_basename); ats_free(m_filename); ats_free(m_alt_filename); @@ -311,12 +310,9 @@ LogObject::add_loghost(LogHost * host, bool copy) // A LogObject either writes to a file, or sends to a collation host, but // not both. By default, it writes to a file. If a LogHost is specified, - // then delete the LogFile object + // then clear the intelligent Ptr containing LogFile. // - if (m_logFile) { - delete m_logFile; - m_logFile = NULL; - } + m_logFile.clear(); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9410b755/proxy/logging/LogObject.h ---------------------------------------------------------------------- diff --git a/proxy/logging/LogObject.h b/proxy/logging/LogObject.h index 06bf4c9..1c67082 100644 --- a/proxy/logging/LogObject.h +++ b/proxy/logging/LogObject.h @@ -203,7 +203,7 @@ public: public: bool m_auto_created; LogFormat * m_format; - LogFile *m_logFile; + Ptr<LogFile> m_logFile; LogFilterList m_filter_list; LogHostList m_host_list;