java.io.IOException: Connection reset by peer

873 views
Skip to first unread message

josep...@wildworks.com

unread,
Oct 12, 2016, 12:23:14 PM10/12/16
to vert.x

Our vertx server is running great.  However, our clients connecting to the server are naughty and often close the connection while the server is still busy.

We routinely get:

Oct 12, 2016 4:05:00 PM io.vertx.core.net.impl.ConnectionBase
SEVERE: java.io.IOException: Connection reset by peer

Which makes our logs noisy.  We like clean logs.  Is there a way to squelch this otherwise harmless exception?

Julien Viet

unread,
Oct 12, 2016, 3:35:32 PM10/12/16
to ve...@googlegroups.com
Hi,

connection reset is not distinguishable in Java from other socket exceptions (see https://bugs.openjdk.java.net/browse/JDK-8167161)

which means that distinguishing this exception from other SocketException implies to parse the exception message.

Julien

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/d9eeecd4-0c6e-4c1e-b7a5-873ee590b10c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Fox

unread,
Oct 12, 2016, 6:04:02 PM10/12/16
to vert.x
Most logging frameworks allow you to filter out exceptions on a per class level
Message has been deleted

josep...@wildworks.com

unread,
Oct 14, 2016, 11:42:48 AM10/14/16
to vert.x
Based a bit on input, I've figured out how to disable these using the default java.util logger.  Posting this for any others wishing to squelch these log entries.  There may be more efficient ways to do this, but this works great in our app now.
I just run this at the init of my app using  myApp.VertxLogFilter.init();  I did it this way rather than load a filter with VM options so the deployment has less to configure for our infra team.

package myApp;


import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.Filter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.io.File;


public class VertxLogFilter implements Filter
{


   
private final String FILTER = "forcibly closed by the remote";
   
private final String CLASS = "io.vertx.core.net.impl.ConnectionBase";


   
@Override
   
public boolean isLoggable(LogRecord record)
   
{
       
if (record == null)
       
{
           
return false;
       
}
       
String loggerName = record.getLoggerName();
       
if (loggerName.equals(CLASS))
       
{
           
String message = record.getMessage();
           
if (message != null)
           
{
               
if (message.contains(FILTER))
               
{
                   
return false;
               
}
               
return true;
           
}
           
return false;
       
}
       
return true;
   
}


   
public static void init(Level level)
   
{
       
Logger rootLogger = Logger.getLogger("");
       
for (Handler handler : rootLogger.getHandlers())
       
{
            handler
.setLevel(level);
            handler
.setFilter(new VertxLogFilter());
       
}
        rootLogger
.setLevel(level);
   
}


   
public static void init()
   
{
       
File file = new File("config/logger.properties");
       
if (file.exists())
       
{
            fileInit
();
       
} else
       
{
            init
(Level.WARNING);
       
}
   
}


   
/**
     * Loads from file
     * Example config/logger.properties file:
     * handlers=java.util.logging.ConsoleHandler
     * .level=WARNING
     * java.util.logging.ConsoleHandler.level=WARNING
     * java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
     * java.util.logging.ConsoleHandler.filter=myApp.VertxLogFilter
     */

   
public static void fileInit()
   
{
       
LogManager logManager = LogManager.getLogManager();
       
try
       
{
            logManager
.readConfiguration(new FileInputStream("config/logger.properties"));
       
} catch (IOException exception)
       
{
           
System.err.println("Error loading config/logger.properties");
       
}
   
}
}


Reply all
Reply to author
Forward
0 new messages