From 63ab0d6f6383d64f39aee25710b1e0e38ec3cca1 Mon Sep 17 00:00:00 2001 From: James Tomson Date: Wed, 7 Dec 2022 17:50:17 -0500 Subject: [PATCH 1/4] allow max logline size to be set via env var --- src/agent/Core/SpawningKit/PipeWatcher.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/agent/Core/SpawningKit/PipeWatcher.h b/src/agent/Core/SpawningKit/PipeWatcher.h index 1e3830471f..f3834b9475 100644 --- a/src/agent/Core/SpawningKit/PipeWatcher.h +++ b/src/agent/Core/SpawningKit/PipeWatcher.h @@ -63,6 +63,8 @@ class PipeWatcher: public boost::enable_shared_from_this { string logFile; boost::mutex startSyncher; boost::condition_variable startCond; + size_t bufSize; + char *buf; static void threadMain(boost::shared_ptr self) { TRACE_POINT(); @@ -90,11 +92,12 @@ class PipeWatcher: public boost::enable_shared_from_this { UPDATE_TRACE_POINT(); while (!boost::this_thread::interruption_requested()) { - char buf[1024 * 8]; ssize_t ret; + + buf[0] = '\0'; UPDATE_TRACE_POINT(); - ret = syscalls::read(fd, buf, sizeof(buf)); + ret = syscalls::read(fd, buf, bufSize); if (ret == 0) { break; } else if (ret == -1) { @@ -150,7 +153,9 @@ class PipeWatcher: public boost::enable_shared_from_this { appGroupName(_appGroupName), appLogFile(_appLogFile), pid(_pid), - started(false) + started(false), + bufSize(1024 * 8), + buf(NULL) { } void setLogFile(const string &path) { @@ -158,6 +163,12 @@ class PipeWatcher: public boost::enable_shared_from_this { } void initialize() { + const char *envMaxLogBytes = getenv("PASSENGER_MAX_LOG_LINE_LENGTH_BYTES"); + if (envMaxLogBytes != NULL && *envMaxLogBytes != '\0') { + bufSize = atoi(envMaxLogBytes); + } + buf = new char[bufSize]; + oxt::thread(boost::bind(threadMain, shared_from_this()), "PipeWatcher: PID " + toString(pid) + " " + name + ", fd " + toString(fd), POOL_HELPER_THREAD_STACK_SIZE); From 36fa68ccc7846034e0326d69933ad72bb163074b Mon Sep 17 00:00:00 2001 From: James Tomson Date: Thu, 8 Dec 2022 12:21:01 -0500 Subject: [PATCH 2/4] add pipewatch dtor and cleanup buffer --- src/agent/Core/SpawningKit/PipeWatcher.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/agent/Core/SpawningKit/PipeWatcher.h b/src/agent/Core/SpawningKit/PipeWatcher.h index f3834b9475..63321e688f 100644 --- a/src/agent/Core/SpawningKit/PipeWatcher.h +++ b/src/agent/Core/SpawningKit/PipeWatcher.h @@ -158,6 +158,12 @@ class PipeWatcher: public boost::enable_shared_from_this { buf(NULL) { } + ~PipeWatcher() { + if (buf != NULL) { + delete[] buf; + } + } + void setLogFile(const string &path) { logFile = path; } From 9028e7f0f7810864aa3561537f3e86757ca63831 Mon Sep 17 00:00:00 2001 From: James Tomson Date: Thu, 8 Dec 2022 12:33:17 -0500 Subject: [PATCH 3/4] delete[] is fine w/ NULL --- src/agent/Core/SpawningKit/PipeWatcher.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/agent/Core/SpawningKit/PipeWatcher.h b/src/agent/Core/SpawningKit/PipeWatcher.h index 63321e688f..e83a4b9173 100644 --- a/src/agent/Core/SpawningKit/PipeWatcher.h +++ b/src/agent/Core/SpawningKit/PipeWatcher.h @@ -159,9 +159,7 @@ class PipeWatcher: public boost::enable_shared_from_this { { } ~PipeWatcher() { - if (buf != NULL) { - delete[] buf; - } + delete[] buf; } void setLogFile(const string &path) { From 6050eda8fdef78e5930fc21be8aebbf131b63149 Mon Sep 17 00:00:00 2001 From: James Tomson Date: Wed, 18 Jan 2023 10:48:31 -0500 Subject: [PATCH 4/4] update CHANGELOG for max log line length env var --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index ce13d81ba9..ee98c9aa81 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ Release 6.0.17 (Not yet released) * Upgrades preferred Nginx to 1.22.1 from 1.20.2. * Changes minimum supported macOS version to 10.14 Mojave. * Adds support for arm (aarch64) rpm packages. + * Adds support for a `PASSENGER_MAX_LOG_LINE_LENGTH_BYTES` environment variable. The default length remains at 8KB. Closes GH-2413. * Updated various library versions used in precompiled binaries (used for e.g. gem installs): - ccache: 4.6.3 → 4.7.4 - curl: 7.86.0 → 7.87.0