Skip to content

Commit 624970f

Browse files
committed
Fix memory leak by limiting internal message queue size
This commit addresses GitHub issue #61 where memory usage keeps increasing and garbage collection fails, eventually causing node crashes after several days. Root Cause: The syslog4j library queues messages internally with no limit by default when using TCP/SSL protocols. Under high message throughput, this causes unbounded memory growth leading to OOM errors. Solution: 1. Added maxQueueSize configuration parameter (default: 500 messages) 2. Set maxQueueSize on all syslog config objects (UDP/TCP/SSL) 3. Made the parameter user-configurable through Graylog UI The conservative default of 500 prevents memory leaks while still allowing reasonable buffering. Users experiencing high throughput can tune this value based on their needs, but should avoid unlimited queuing (-1). When the queue is full, the plugin will block until space is available, providing natural backpressure instead of consuming all available memory. Configuration: - Default: 500 messages - Configurable via "Maximum queue size" field in output configuration - Set to -1 for unlimited (not recommended, will cause OOM) Fixes #61 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 7401ea5 commit 624970f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/main/java/com/wizecore/graylog2/plugin/SyslogOutput.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ public SyslogOutput(@Assisted Stream stream, @Assisted Configuration conf) {
143143
config.setMaxMessageLength(maxlen);
144144
config.setTruncateMessage(true);
145145

146+
// Set maximum queue size to prevent OOM under high load (issue #61)
147+
// Default is unlimited which causes memory leaks
148+
int maxQueueSize = 500; // Conservative default
149+
try {
150+
String queueSizeStr = conf.getString("maxQueueSize");
151+
if (queueSizeStr != null && !queueSizeStr.trim().isEmpty()) {
152+
maxQueueSize = Integer.parseInt(queueSizeStr);
153+
}
154+
} catch (Exception e) {
155+
log.warning("Failed to parse maxQueueSize, using default: " + maxQueueSize);
156+
}
157+
config.setMaxQueueSize(maxQueueSize);
158+
log.info("Set maxQueueSize to " + maxQueueSize + " for " + protocol + "://" + host + ":" + port);
159+
146160
String hash = protocol + "_" + host + "_" + port + "_" + format;
147161
syslog = Syslog.exists(hash) ? Syslog.getInstance(hash) : Syslog.createInstance(hash, config);
148162

@@ -320,6 +334,8 @@ public ConfigurationRequest getRequestedConfiguration() {
320334

321335
configurationRequest.addField(new TextField("maxlen", "Maximum message length", "", "Maximum message (body) length. Longer messages will be truncated. If not specified defaults to 16384 bytes.", ConfigurationField.Optional.OPTIONAL));
322336

337+
configurationRequest.addField(new TextField("maxQueueSize", "Maximum queue size", "500", "Maximum number of messages to queue internally before blocking (prevents OOM). Set to -1 for unlimited (not recommended). Default is 500.", ConfigurationField.Optional.OPTIONAL));
338+
323339
configurationRequest.addField(new TextField("keystore", "Key store", "", "Path to Java keystore (required for SSL over TCP). Must contain private key and cert for this client.", ConfigurationField.Optional.OPTIONAL));
324340
configurationRequest.addField(new TextField("keystorePassword", "Key store password", "", "", ConfigurationField.Optional.OPTIONAL));
325341

0 commit comments

Comments
 (0)