Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the issue of NPE caused by unexpected exceptions thrown during the use of AsyncClient #14556

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.lang.reflect.InvocationTargetException;
import java.net.ConnectException;
import java.net.SocketException;
import java.util.Optional;

/**
* This class defines the failed interfaces that thrift client needs to support so that the Thrift
Expand Down Expand Up @@ -107,11 +108,17 @@ static void resolveException(Throwable t, ThriftClient o) {
static boolean isConnectionBroken(Throwable cause) {
return (cause instanceof SocketException && cause.getMessage().contains("Broken pipe"))
|| (cause instanceof TTransportException
&& (cause.getMessage().contains("Socket is closed by peer")
|| cause.getMessage().contains("Read call frame size failed")))
&& (hasExpectedMessage(cause, "Socket is closed by peer")
|| hasExpectedMessage(cause, "Read call frame size failed")))
|| (cause instanceof IOException
&& (cause.getMessage().contains("Connection reset by peer")
|| cause.getMessage().contains("Broken pipe")))
|| (cause instanceof ConnectException && cause.getMessage().contains("Connection refused"));
&& (hasExpectedMessage(cause, "Connection reset by peer")
|| hasExpectedMessage(cause, "Broken pipe")))
|| (cause instanceof ConnectException && hasExpectedMessage(cause, "Connection refused"));
}

static boolean hasExpectedMessage(Throwable cause, String expectedMessage) {
return Optional.ofNullable(cause.getMessage())
.map(m -> m.contains(expectedMessage))
.orElse(false);
}
}
Loading