Skip to content

Commit

Permalink
THRIFT-5502 Log SocketException at WARN level only + Fix formatting
Browse files Browse the repository at this point in the history
Client: java
Patch: Sylwester Lachiewicz & Christopher Tubbs

This closes #2608
  • Loading branch information
slachiewicz authored and Jens-G committed Aug 25, 2022
1 parent d5c6697 commit 0aa108f
Showing 1 changed file with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.thrift.server;

import java.net.SocketException;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
Expand Down Expand Up @@ -253,18 +254,7 @@ public void run() {
processor.process(inputProtocol, outputProtocol);
}
} catch (Exception x) {
LOGGER.debug("Error processing request", x);

// We'll usually receive RuntimeException types here
// Need to unwrap to ascertain real causing exception before we choose to ignore
// Ignore err-logging all transport-level/type exceptions
if (!isIgnorableException(x)) {
// Log the exception at error level and continue
LOGGER.error(
(x instanceof TException ? "Thrift " : "")
+ "Error occurred during processing of message.",
x);
}
logException(x);
} finally {
if (eventHandler.isPresent()) {
eventHandler.get().deleteContext(connectionContext, inputProtocol, outputProtocol);
Expand All @@ -281,7 +271,11 @@ public void run() {
}
}

private boolean isIgnorableException(Exception x) {
private void logException(Exception x) {
LOGGER.debug("Error processing request", x);
// We'll usually receive RuntimeException types here
// Need to unwrap to ascertain real causing exception before we choose to ignore
// Ignoring err-logging all transport-level/type exceptions and SocketExceptions
TTransportException tTransportException = null;

if (x instanceof TTransportException) {
Expand All @@ -294,10 +288,21 @@ private boolean isIgnorableException(Exception x) {
switch (tTransportException.getType()) {
case TTransportException.END_OF_FILE:
case TTransportException.TIMED_OUT:
return true;
return; // don't log these
}
if (tTransportException.getCause() != null
&& (tTransportException.getCause() instanceof SocketException)) {
LOGGER.warn(
"SocketException occurred during processing of message.",
tTransportException.getCause());
return;
}
}
return false;
// Log the exception at error level and continue
LOGGER.error(
(x instanceof TException ? "Thrift " : "")
+ "Error occurred during processing of message.",
x);
}
}
}

0 comments on commit 0aa108f

Please sign in to comment.