@@ -93,13 +93,23 @@ public SyslogOutput(@Assisted Stream stream, @Assisted Configuration conf) {
9393 format = "plain" ;
9494 }
9595
96+ int maxQueueSize = 500 ;
97+ String queueSizeStr = conf .getString ("maxQueueSize" );
98+ if (queueSizeStr != null && !queueSizeStr .trim ().isEmpty ()) {
99+ maxQueueSize = Integer .parseInt (queueSizeStr );
100+ }
101+
96102 log .info ("Creating syslog output " + protocol + "://" + host + ":" + port + ", format " + format );
97103 SyslogConfigIF config = null ;
98104 if (protocol .toLowerCase ().equals ("udp" )) {
99- config = new UDPNetSyslogConfig ();
105+ UDPNetSyslogConfig updConfig = new UDPNetSyslogConfig ();
106+ udpConfig .setMaxQueueSize (maxQueueSize );
107+ config = udpConfig ;
100108 } else
101109 if (protocol .toLowerCase ().equals ("tcp" )) {
102- config = new TCPNetSyslogConfig ();
110+ TCPNetSyslogConfig tcpConfig = new TCPNetSyslogConfig ();
111+ tcpConfig .setMaxQueueSize (maxQueueSize );
112+ config = tcpConfig ;
103113 } else
104114 if (protocol .toLowerCase ().equals ("tcp-ssl" )) {
105115 CustomSSLSyslogConfig sslConfig = new CustomSSLSyslogConfig ();
@@ -129,6 +139,7 @@ public SyslogOutput(@Assisted Stream stream, @Assisted Configuration conf) {
129139 sslConfig .setKeyStorePassword (ksp );
130140 sslConfig .setTrustStore (ts );
131141 sslConfig .setTrustStorePassword (tsp );
142+ sslConfig .setMaxQueueSize (maxQueueSize );
132143 } else {
133144 throw new IllegalArgumentException ("Unknown protocol: " + protocol );
134145 }
@@ -144,23 +155,6 @@ public SyslogOutput(@Assisted Stream stream, @Assisted Configuration conf) {
144155 config .setMaxMessageLength (maxlen );
145156 config .setTruncateMessage (true );
146157
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-
164158 String hash = protocol + "_" + host + "_" + port + "_" + format ;
165159 syslog = Syslog .exists (hash ) ? Syslog .getInstance (hash ) : Syslog .createInstance (hash , config );
166160
0 commit comments