Skip to content

Commit d89dd2d

Browse files
author
AgentK
authored
netty: log SocketExceptions at FINE, too
This PR changes the `NettyServerTransport#getLogLevel` method to log `SocketException`s to `LogLevel.FINE`, rather than exclusively pure IOExceptions. This may fix an unintentional regression introduced in c166ec2, although the message in my java version (14.0.1) wouldn't have passed the old logic for quieting either. This also fixes the issue raised in #6423 that was locked for inactivity. This fixes ``` [2020/05/14 20:21:52 INFO] [io.grpc.netty.NettyServerTransport.connections] Transport failed java.net.SocketException: Connection reset at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:345) at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:376) at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288) at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1125) at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:347) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:677) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:612) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:529) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:491) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:832) ``` being logged to level INFO, which occurs whenever a socket is improperly closed by the client, such as with the grpc-health-probe (They've got an [open issue](grpc-ecosystem/grpc-health-probe#34) for this)
1 parent 4a80b42 commit d89dd2d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

netty/src/main/java/io/grpc/netty/NettyServerTransport.java

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import io.netty.util.concurrent.GenericFutureListener;
3939
import java.io.IOException;
4040
import java.net.SocketAddress;
41+
import java.net.SocketException;
4142
import java.util.List;
4243
import java.util.concurrent.ScheduledExecutorService;
4344
import java.util.logging.Level;
@@ -186,6 +187,7 @@ Channel channel() {
186187
@VisibleForTesting
187188
static Level getLogLevel(Throwable t) {
188189
if (t.getClass().equals(IOException.class)
190+
|| t.getClass().equals(SocketException.class)
189191
|| QUIET_EXCEPTIONS.contains(t.getClass().getSimpleName())) {
190192
return Level.FINE;
191193
}

netty/src/test/java/io/grpc/netty/NettyServerTransportTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.junit.Assert.assertNull;
2323

2424
import java.io.IOException;
25+
import java.net.SocketException;
2526
import java.util.logging.Level;
2627
import org.junit.Test;
2728
import org.junit.runner.RunWith;
@@ -34,6 +35,11 @@ public void unknownException() {
3435
assertEquals(Level.INFO, getLogLevel(new Exception()));
3536
}
3637

38+
@Test
39+
public void socketException() {
40+
assertEquals(Level.FINE, getLogLevel(new SocketException("Connection reset")));
41+
}
42+
3743
@Test
3844
public void ioException() {
3945
assertEquals(Level.FINE, getLogLevel(new IOException("Connection reset by peer")));

0 commit comments

Comments
 (0)