-
Notifications
You must be signed in to change notification settings - Fork 844
Description
Log files created with mode ascii_pipe are unlinked upon logging.yaml configuration reload. This means that the named pipe will keep on working as expected only util a process is reading from it. Restarting the reader process breaks logging. The bug has been reproduced against master (1fa443c).
Setup
Traffic Server was built from master with:
autoreconf -if
./configure --enable-layout=Debian --sysconfdir=/etc/trafficserver --libdir=/usr/lib/trafficserver --libexecdir=/usr/lib/trafficserver/modules
make -j4The following configuration was used:
# /etc/trafficserver/records.config
CONFIG proxy.config.bin_path STRING /home/ema/dev/trafficserver/src/traffic_server/
CONFIG proxy.config.diags.debug.enabled INT 1
CONFIG proxy.config.diags.debug.tags STRING log-file# /etc/trafficserver/logging.yaml
formats:
- name: common
format: 'test: %<chi> - %<caun> [%<cqtn>] "%<cqtx>" %<pssc> %<pscl>'
logs:
- filename: fifologs
format: common
mode: ascii_pipeThe traffic_manager process was started with:
sudo -u trafficserver ./src/traffic_manager/traffic_manager --nosyslog
Reproducing the issue
Startup with no reader
Upon startup, the fifologs.pipe named pipe is created, but opening it fails (as expected) due to lack of readers:
[Nov 21 09:38:01.876] traffic_server DEBUG: <LogFile.cc:80 (LogFile)> (log-file) exiting LogFile constructor, m_name=/var/log/trafficserver/fifologs.pipe, this=0x55ea88a8bfb0
[Nov 21 09:38:01.876] traffic_server DEBUG: <LogFile.cc:175 (open_file)> (log-file) Created named pipe /var/log/trafficserver/fifologs.pipe for logging
[Nov 21 09:38:01.876] traffic_server DEBUG: <LogFile.cc:179 (open_file)> (log-file) attempting to open pipe /var/log/trafficserver/fifologs.pipe
[Nov 21 09:38:01.876] traffic_server DEBUG: <LogFile.cc:182 (open_file)> (log-file) no readers for pipe /var/log/trafficserver/fifologs.pipe
[Nov 21 09:38:01.876] traffic_server DEBUG: <LogFile.cc:80 (LogFile)> (log-file) exiting LogFile constructor, m_name=/var/log/trafficserver/error.log, this=0x55ea88a88340
[Nov 21 09:38:01.876] traffic_server DEBUG: <LogFile.cc:80 (LogFile)> (log-file) exiting LogFile constructor, m_name=/var/log/trafficserver/scrapfile.log, this=0x55ea88a8ec30
Issuing an HTTP request to traffic_server results in another failed attempt to open the pipe in order to write a log entry for the transaction:
[Nov 21 09:39:06.998] [LOG_PREPROC 0] DEBUG: <LogFile.cc:427 (write_ascii_logbuffer3)> (log-file) entering LogFile::write_ascii_logbuffer3 for /var/log/trafficserver/fifologs.pipe (this=0x55ea88a8bfb0)
[Nov 21 09:39:06.998] [LOG_PREPROC 0] DEBUG: <LogFile.cc:427 (write_ascii_logbuffer3)> (log-file) entering LogFile::write_ascii_logbuffer3 for /var/log/trafficserver/error.log (this=0x55ea88a88340)
[Nov 21 09:39:06.998] [LOG_FLUSH] DEBUG: <LogFile.cc:179 (open_file)> (log-file) attempting to open pipe /var/log/trafficserver/fifologs.pipe
[Nov 21 09:39:06.998] [LOG_FLUSH] DEBUG: <LogFile.cc:182 (open_file)> (log-file) no readers for pipe /var/log/trafficserver/fifologs.pipe
Proper logging upon reader startup
Starting a reader (eg: cat /var/log/trafficserver/fifologs.pipe) and performing another HTTP request:
[Nov 21 09:39:56.139] [LOG_PREPROC 0] DEBUG: <LogFile.cc:427 (write_ascii_logbuffer3)> (log-file) entering LogFile::write_ascii_logbuffer3 for /var/log/trafficserver/fifologs.pipe (this=0x55ea88a8bfb0)
[Nov 21 09:39:56.139] [LOG_PREPROC 0] DEBUG: <LogFile.cc:427 (write_ascii_logbuffer3)> (log-file) entering LogFile::write_ascii_logbuffer3 for /var/log/trafficserver/error.log (this=0x55ea88a88340)
[Nov 21 09:39:56.139] [LOG_FLUSH] DEBUG: <LogFile.cc:179 (open_file)> (log-file) attempting to open pipe /var/log/trafficserver/fifologs.pipe
At this point the pipe is opened successfully, and logs are shown as expected by cat.
lsof /var/log/trafficserver/fifologs.pipe
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
cat 4165 root 3r FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe
[TS_MAIN] 31309 trafficserver 43w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe
Trigger logging.yaml configuration reload and fifo deletion
After adding an empty line to logging.yaml and triggering a configuration reload with pkill -HUP traffic_manager:
[Nov 21 10:05:09.927] [LOG_FLUSH] DEBUG: <LogFile.cc:80 (LogFile)> (log-file) exiting LogFile constructor, m_name=/var/log/trafficserver/fifologs.pipe, this=0x1543bc008cc0
[Nov 21 10:05:09.929] [LOG_FLUSH] DEBUG: <LogFile.cc:175 (open_file)> (log-file) Created named pipe /var/log/trafficserver/fifologs.pipe for logging
[Nov 21 10:05:09.929] [LOG_FLUSH] DEBUG: <LogFile.cc:179 (open_file)> (log-file) attempting to open pipe /var/log/trafficserver/fifologs.pipe
[Nov 21 10:05:09.929] [LOG_FLUSH] DEBUG: <LogFile.cc:182 (open_file)> (log-file) no readers for pipe /var/log/trafficserver/fifologs.pipe
[Nov 21 10:05:09.929] [LOG_FLUSH] DEBUG: <LogFile.cc:80 (LogFile)> (log-file) exiting LogFile constructor, m_name=/var/log/trafficserver/error.log, this=0x1543bc007880
[Nov 21 10:05:09.929] [LOG_FLUSH] DEBUG: <LogFile.cc:115 (~LogFile)> (log-file) entering LogFile destructor, this=0x1543bc008cc0
[Nov 21 10:05:09.929] [LOG_FLUSH] DEBUG: <LogFile.cc:119 (~LogFile)> (log-file) exiting LogFile destructor, this=0x1543bc008cc0
[Nov 21 10:05:09.929] [LOG_FLUSH] DEBUG: <LogFile.cc:115 (~LogFile)> (log-file) entering LogFile destructor, this=0x1543bc007880
[Nov 21 10:05:09.929] [LOG_FLUSH] DEBUG: <LogFile.cc:119 (~LogFile)> (log-file) exiting LogFile destructor, this=0x1543bc007880
Once this happens, lsof /var/log/trafficserver/fifologs.pipe reports the pipe as not being open by cat and TS_MAIN any longer. The fifo results now deleted:
lsof | grep /var/log/trafficserver/fifologs.pipe
[TS_MAIN] 7855 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
traffic_s 7855 7869 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_NET 7855 7872 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_NET 7855 7873 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_NET 7855 7874 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_NET 7855 7875 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_NET 7855 7876 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_NET 7855 7877 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[LOG_PREP 7855 7878 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[LOG_FLUS 7855 7879 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_AIO 7855 7880 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_AIO 7855 7881 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_AIO 7855 7882 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_AIO 7855 7883 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_AIO 7855 7884 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_AIO 7855 7885 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_AIO 7855 7886 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_AIO 7855 7887 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ACCEPT 7855 7888 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ACCEPT 7855 7889 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_TASK 7855 7890 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
[ET_TASK 7855 7891 trafficserver 44w FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
cat 8018 root 3r FIFO 253,1 0t0 917531 /var/log/trafficserver/fifologs.pipe (deleted)
Restarting the reader
Stopping the cat process and starting a new one results in all logs being lost:
[Nov 21 10:08:44.556] [LOG_PREPROC 0] DEBUG: <LogFile.cc:427 (write_ascii_logbuffer3)> (log-file) entering LogFile::write_ascii_logbuffer3 for /var/log/trafficserver/fifologs.pipe (this=0x55f66c78ff30)
[Nov 21 10:08:44.556] [LOG_FLUSH] ERROR: Failed to write log to /var/log/trafficserver/fifologs.pipe: [tried 88, wrote 0, Broken pipe]
Avoiding unlink
diff --git a/proxy/logging/LogObject.cc b/proxy/logging/LogObject.cc
index c745bddb2..0d4ed90a9 100644
--- a/proxy/logging/LogObject.cc
+++ b/proxy/logging/LogObject.cc
@@ -1009,7 +1009,7 @@ LogObjectManager::_solve_filename_conflicts(LogObject *log_object, int maxConfli
roll_file = false;
} else {
if (S_ISFIFO(s.st_mode)) {
- unlink(filename);
+ //unlink(filename);
roll_file = false;
}
}With the patch above applied, a logging.yaml reload does not remove the pipe, and the reader (cat in our example) can be restarted at will without breaking logging. Notice how in this case there is no no readers for pipe error:
[Nov 21 10:59:19.579] [LOG_FLUSH] DEBUG: <LogFile.cc:80 (LogFile)> (log-file) exiting LogFile constructor, m_name=/var/log/trafficserver/fifologs.pipe, this=0x14dfac008c80
[Nov 21 10:59:19.579] [LOG_FLUSH] DEBUG: <LogFile.cc:179 (open_file)> (log-file) attempting to open pipe /var/log/trafficserver/fifologs.pipe
[Nov 21 10:59:19.579] [LOG_FLUSH] DEBUG: <LogFile.cc:80 (LogFile)> (log-file) exiting LogFile constructor, m_name=/var/log/trafficserver/error.log, this=0x14dfac007840
[Nov 21 10:59:19.580] [LOG_FLUSH] DEBUG: <LogFile.cc:115 (~LogFile)> (log-file) entering LogFile destructor, this=0x14dfac008c80
[Nov 21 10:59:19.580] [LOG_FLUSH] DEBUG: <LogFile.cc:119 (~LogFile)> (log-file) exiting LogFile destructor, this=0x14dfac008c80
[Nov 21 10:59:19.580] [LOG_FLUSH] DEBUG: <LogFile.cc:115 (~LogFile)> (log-file) entering LogFile destructor, this=0x14dfac007840
[Nov 21 10:59:19.580] [LOG_FLUSH] DEBUG: <LogFile.cc:119 (~LogFile)> (log-file) exiting LogFile destructor, this=0x14dfac007840
However, this causes TS_MAIN to open a new file descriptor every time logging.yaml is reloaded. For example, after 3 reloads:
lsof /var/log/trafficserver/fifologs.pipe
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
[TS_MAIN] 30483 trafficserver 40w FIFO 253,1 0t0 925539 /var/log/trafficserver/fifologs.pipe
[TS_MAIN] 30483 trafficserver 44w FIFO 253,1 0t0 925539 /var/log/trafficserver/fifologs.pipe
[TS_MAIN] 30483 trafficserver 45w FIFO 253,1 0t0 925539 /var/log/trafficserver/fifologs.pipe
[TS_MAIN] 30483 trafficserver 47w FIFO 253,1 0t0 925539 /var/log/trafficserver/fifologs.pipe
cat 31587 root 3r FIFO 253,1 0t0 925539 /var/log/trafficserver/fifologs.pipe
The file descriptor leak shown above should clearly be avoided, though on a busy server it is arguably an improvement over breaking logging altogether, possibly filling up /var with Failed to write log entries.