Skip to content

Commit c166ec2

Browse files
committed
netty: use FINE log for pure IOExceptions
1 parent 03c75e1 commit c166ec2

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

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

+2-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.google.common.annotations.VisibleForTesting;
2020
import com.google.common.base.MoreObjects;
2121
import com.google.common.base.Preconditions;
22-
import com.google.common.collect.ImmutableList;
2322
import com.google.common.util.concurrent.ListenableFuture;
2423
import com.google.common.util.concurrent.SettableFuture;
2524
import io.grpc.InternalChannelz.SocketStats;
@@ -50,11 +49,6 @@ class NettyServerTransport implements ServerTransport {
5049
// connectionLog is for connection related messages only
5150
private static final Logger connectionLog = Logger.getLogger(
5251
String.format("%s.connections", NettyServerTransport.class.getName()));
53-
// Some exceptions are not very useful and add too much noise to the log
54-
private static final ImmutableList<String> QUIET_ERRORS = ImmutableList.of(
55-
"Connection reset by peer",
56-
"An existing connection was forcibly closed by the remote host",
57-
"An established connection was aborted by the software in your host machine");
5852

5953
private final InternalLogId logId;
6054
private final Channel channel;
@@ -184,12 +178,8 @@ Channel channel() {
184178
*/
185179
@VisibleForTesting
186180
static Level getLogLevel(Throwable t) {
187-
if (t instanceof IOException && t.getMessage() != null) {
188-
for (String msg : QUIET_ERRORS) {
189-
if (t.getMessage().contains(msg)) {
190-
return Level.FINE;
191-
}
192-
}
181+
if (t.getClass().equals(IOException.class)) {
182+
return Level.FINE;
193183
}
194184
return Level.INFO;
195185
}

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

+11-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.grpc.netty;
1818

19+
import static com.google.common.truth.Truth.assertThat;
1920
import static io.grpc.netty.NettyServerTransport.getLogLevel;
2021
import static org.junit.Assert.assertEquals;
2122
import static org.junit.Assert.assertNull;
@@ -34,27 +35,25 @@ public void unknownException() {
3435
}
3536

3637
@Test
37-
public void quiet() {
38+
public void ioException() {
3839
assertEquals(Level.FINE, getLogLevel(new IOException("Connection reset by peer")));
3940
assertEquals(Level.FINE, getLogLevel(new IOException(
4041
"An existing connection was forcibly closed by the remote host")));
4142
}
4243

4344
@Test
44-
public void quiet_prefixed() {
45-
assertEquals(Level.FINE, getLogLevel(new IOException(
46-
"syscall:read(..) failed: Connection reset by peer")));
45+
public void ioException_nullMessage() {
46+
IOException e = new IOException();
47+
assertNull(e.getMessage());
48+
assertEquals(Level.FINE, getLogLevel(e));
4749
}
4850

4951
@Test
50-
public void nonquiet() {
51-
assertEquals(Level.INFO, getLogLevel(new IOException("foo")));
52-
}
52+
public void extendedIoException() {
53+
class ExtendedIoException extends IOException {}
5354

54-
@Test
55-
public void nullMessage() {
56-
IOException e = new IOException();
57-
assertNull(e.getMessage());
58-
assertEquals(Level.INFO, getLogLevel(e));
55+
ExtendedIoException e = new ExtendedIoException();
56+
assertThat(e.getMessage()).isNull();
57+
assertThat(getLogLevel(e)).isEqualTo(Level.INFO);
5958
}
6059
}

0 commit comments

Comments
 (0)