Skip to content

Commit d7c4dd2

Browse files
committed
fix: fix retry policy.
1 parent 8f6515b commit d7c4dd2

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

databend-client/src/main/java/com/databend/client/RetryPolicy.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.io.IOException;
2424
import java.net.ConnectException;
2525
import java.sql.SQLException;
26+
import java.util.Arrays;
27+
import java.util.List;
2628
import java.util.Random;
2729
import java.util.logging.Level;
2830
import java.util.logging.Logger;
@@ -70,8 +72,21 @@ public boolean shouldRetry(int code, String body) {
7072
return false;
7173
}
7274

75+
private static final List<String> ERROR_KEYWORDS = Arrays.asList(
76+
"unexpected end of stream",
77+
"timeout",
78+
"connection refused"
79+
);
80+
7381
public boolean shouldRetry(IOException e) {
74-
return e.getCause() instanceof ConnectException;
82+
if (e.getCause() instanceof ConnectException) {
83+
return true;
84+
}
85+
String msg = e.getMessage();
86+
if (msg == null) {
87+
return false;
88+
}
89+
return ERROR_KEYWORDS.stream().anyMatch(keyword -> msg.contains(keyword));
7590
}
7691

7792
private static long calculateBackoffInterval(int attempts) {

0 commit comments

Comments
 (0)