|
18 | 18 | import org.graylog2.syslog4j.SyslogConfigIF; |
19 | 19 | import org.graylog2.syslog4j.SyslogIF; |
20 | 20 | import org.graylog2.syslog4j.SyslogRuntimeException; |
| 21 | +import org.graylog2.syslog4j.impl.AbstractSyslogConfigIF; |
21 | 22 | import org.graylog2.syslog4j.impl.message.processor.SyslogMessageProcessor; |
22 | 23 | import org.graylog2.syslog4j.impl.message.processor.structured.StructuredSyslogMessageProcessor; |
23 | 24 | import org.graylog2.syslog4j.impl.net.tcp.TCPNetSyslogConfig; |
@@ -143,6 +144,23 @@ public SyslogOutput(@Assisted Stream stream, @Assisted Configuration conf) { |
143 | 144 | config.setMaxMessageLength(maxlen); |
144 | 145 | config.setTruncateMessage(true); |
145 | 146 |
|
| 147 | + // Set maximum queue size to prevent OOM under high load (issue #61) |
| 148 | + // Default is unlimited which causes memory leaks |
| 149 | + int maxQueueSize = 500; // Conservative default |
| 150 | + try { |
| 151 | + String queueSizeStr = conf.getString("maxQueueSize"); |
| 152 | + if (queueSizeStr != null && !queueSizeStr.trim().isEmpty()) { |
| 153 | + maxQueueSize = Integer.parseInt(queueSizeStr); |
| 154 | + } |
| 155 | + } catch (Exception e) { |
| 156 | + log.warning("Failed to parse maxQueueSize, using default: " + maxQueueSize); |
| 157 | + } |
| 158 | + // setMaxQueueSize is available on AbstractSyslogConfigIF, which all configs implement |
| 159 | + if (config instanceof AbstractSyslogConfigIF) { |
| 160 | + ((AbstractSyslogConfigIF) config).setMaxQueueSize(maxQueueSize); |
| 161 | + log.info("Set maxQueueSize to " + maxQueueSize + " for " + protocol + "://" + host + ":" + port); |
| 162 | + } |
| 163 | + |
146 | 164 | String hash = protocol + "_" + host + "_" + port + "_" + format; |
147 | 165 | syslog = Syslog.exists(hash) ? Syslog.getInstance(hash) : Syslog.createInstance(hash, config); |
148 | 166 |
|
@@ -320,6 +338,8 @@ public ConfigurationRequest getRequestedConfiguration() { |
320 | 338 |
|
321 | 339 | 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)); |
322 | 340 |
|
| 341 | + 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)); |
| 342 | + |
323 | 343 | 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)); |
324 | 344 | configurationRequest.addField(new TextField("keystorePassword", "Key store password", "", "", ConfigurationField.Optional.OPTIONAL)); |
325 | 345 |
|
|
0 commit comments