-
Notifications
You must be signed in to change notification settings - Fork 556
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
[client-v2] Fix check for ConnectTimeoutException in shouldRetry #2015
Conversation
The catch block accepts ConnectTimeoutException; however, shouldRetry checks for ConnectException
@@ -583,7 +583,7 @@ public boolean shouldRetry(Exception ex, Map<String, Object> requestSettings) { | |||
return retryCauses.contains(ClientFaultCause.NoHttpResponse); | |||
} | |||
|
|||
if (ex instanceof ConnectException) { | |||
if (ex instanceof ConnectTimeoutException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they should be both:
- ConnectException - means that socket failed to connect. When we implement TCP protocol support we might use this exception
- org.apache.hc.client5.http.ConnectTimeoutException is child of java.net.SocketTimeoutException - means that throws when read or accept (according to the JavaDoc of the last one). And ConnectTimeoutException is client specific exception. It will not be thrown by other client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConnectException - means that socket failed to connect. When we implement TCP protocol support we might use this exception
I agree that this is a useful exception to check for, but this particular if block then proceeds to check retryCauses.contains(ClientFaultCause.ConnectTimeout)
, and so ConnectException
doesn't seem applicable (to ClientFaultCause.ConnectTimeout
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is applicable - because ClientFaultCause.ConnectTimeout is about any error while connection initiation.
ConnectException is all about it:
/**
* Signals that an error occurred while attempting to connect a
* socket to a remote address and port. Typically, the connection
* was refused remotely (e.g., no process is listening on the
* remote address/port).
*
* @since 1.1
*/
public class ConnectException extends SocketException
Good day, @janeklb ! You have brought a very good question and I almost agree with your fix. ConnectionException should be in multi-catch. When handling exceptions we are trying to be more generic and we try to avoid mentioning very specific exceptions. In this case both exceptions should be handles - unfortunately AHC 's ConnectTimeoutException doesn't derive from ConnectionException - I think this is wrong impl. Please see my comment in the code. |
I've made this change in Do you think |
|
…ies, add NoHttpResponseException to wrapException
Alrighty. I've pushed the changes I think you were suggesting |
Thank you! |
Summary
The catch block accepts
ConnectTimeoutException
; however,shouldRetry
checks forConnectException
.I think the solution is for
shouldRetry
to test forConnectTimeoutException
, please let me know if that's incorrect so that i can adjust thecatch
clause instead.It's also worth noting that
wrapException
tests forConnectException
; however,wrapException
will never only ever be called withNoHttpResponseException | ConnectionRequestTimeoutException | ConnectTimeoutException
, which makes me wonder if:ConnectException
there should be replaced withNoHttpResponseException
ConnectException
should be added to the multi-catchChecklist
Delete items not relevant to your PR: