From 1f95e5db4c790f0d3b5df226ba5d71708c175f9e Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 31 Jul 2014 18:05:18 -0700 Subject: [PATCH] [#2720] Check if /proc/sys/net/core/somaxconn exists before try to parse it Motivation: As /proc/sys/net/core/somaxconn does not exists on non-linux platforms you see a noisy stacktrace when debug level is enabled while the static method of NetUtil is executed. Modifications: Check if the file exists before try to parse it. Result: Less noisy logging on non-linux platforms. --- .../src/main/java/io/netty/util/NetUtil.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/io/netty/util/NetUtil.java b/common/src/main/java/io/netty/util/NetUtil.java index fe76d97f2b..be42814759 100644 --- a/common/src/main/java/io/netty/util/NetUtil.java +++ b/common/src/main/java/io/netty/util/NetUtil.java @@ -20,6 +20,7 @@ import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; import java.io.BufferedReader; +import java.io.File; import java.io.FileReader; import java.net.Inet4Address; import java.net.Inet6Address; @@ -180,21 +181,26 @@ public final class NetUtil { // Determine the default somaxconn (server socket backlog) value of the platform. int somaxconn = 3072; - BufferedReader in = null; - try { - in = new BufferedReader(new FileReader("/proc/sys/net/core/somaxconn")); - somaxconn = Integer.parseInt(in.readLine()); - logger.debug("/proc/sys/net/core/somaxconn: {}", somaxconn); - } catch (Exception e) { - logger.debug("Failed to get SOMAXCONN", e); - } finally { - if (in != null) { - try { - in.close(); - } catch (Exception e) { - // Ignored. + File file = new File("/proc/sys/net/core/somaxconn"); + if (file.exists()) { + BufferedReader in = null; + try { + in = new BufferedReader(new FileReader("/proc/sys/net/core/somaxconn")); + somaxconn = Integer.parseInt(in.readLine()); + logger.debug("/proc/sys/net/core/somaxconn: {}", somaxconn); + } catch (Exception e) { + logger.debug("Failed to get SOMAXCONN", e); + } finally { + if (in != null) { + try { + in.close(); + } catch (Exception e) { + // Ignored. + } } } + } else { + logger.debug("/proc/sys/net/core/somaxconn not exists. Use default-value: {}", somaxconn); } SOMAXCONN = somaxconn;