Skip to content

Commit d75a0df

Browse files
committed
Throw a configuration error if Netty reserved direct memory is not anough (256MB)
1 parent 16a76b8 commit d75a0df

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/logstash/inputs/beats.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ def create_server
250250
server = org.logstash.beats.Server.new(@host, @port, @client_inactivity_timeout, @executor_threads, @protect_direct_memory)
251251
server.setSslHandlerProvider(new_ssl_handshake_provider(new_ssl_context_builder)) if @ssl_enabled
252252
server
253+
rescue java.lang.IllegalArgumentException => e
254+
configuration_error e.message
253255
end
254256

255257
def run(output_queue)

src/main/java/org/logstash/beats/Server.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.netty.handler.timeout.IdleStateHandler;
1313
import io.netty.util.concurrent.DefaultEventExecutorGroup;
1414
import io.netty.util.concurrent.EventExecutorGroup;
15+
import io.netty.util.internal.PlatformDependent;
1516
import org.apache.logging.log4j.LogManager;
1617
import org.apache.logging.log4j.Logger;
1718
import org.logstash.netty.SslHandlerProvider;
@@ -30,16 +31,26 @@ public class Server {
3031

3132
private final int clientInactivityTimeoutSeconds;
3233

33-
// public Server(String host, int p, int clientInactivityTimeoutSeconds, int threadCount) {
34-
// this(host, p, clientInactivityTimeoutSeconds, threadCount, true);
35-
// }
36-
3734
public Server(String host, int p, int clientInactivityTimeoutSeconds, int threadCount, boolean protectDirectMemory) {
3835
this.host = host;
3936
port = p;
4037
this.clientInactivityTimeoutSeconds = clientInactivityTimeoutSeconds;
4138
beatsHeandlerThreadCount = threadCount;
4239
this.protectDirectMemory = protectDirectMemory;
40+
41+
validateMinimumDirectMemory();
42+
}
43+
44+
/**
45+
* Validate if the configured available direct memory is enough for safe processing, else throws a ConfigurationException
46+
* */
47+
private void validateMinimumDirectMemory() {
48+
long maxDirectMemoryAllocatable = PlatformDependent.maxDirectMemory();
49+
if (maxDirectMemoryAllocatable < 256 * 1024 * 1024) {
50+
long roundedMegabytes = Math.round((double) maxDirectMemoryAllocatable / 1024 / 1024);
51+
throw new IllegalArgumentException("Max direct memory should be at least 256MB but was " + roundedMegabytes + "MB, " +
52+
"please check your MaxDirectMemorySize and io.netty.maxDirectMemory settings");
53+
}
4354
}
4455

4556
public void setSslHandlerProvider(SslHandlerProvider sslHandlerProvider){

0 commit comments

Comments
 (0)