Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Adding retry to getHttpClient when "No System TLS" pops up #491 #597

Merged
merged 2 commits into from
May 30, 2018

Conversation

diemol
Copy link
Contributor

@diemol diemol commented May 27, 2018

To solve #491

@codecov-io
Copy link

codecov-io commented May 27, 2018

Codecov Report

Merging #597 into master will decrease coverage by 0.31%.
The diff coverage is 0%.

@@             Coverage Diff              @@
##             master     #597      +/-   ##
============================================
- Coverage     59.73%   59.42%   -0.32%     
  Complexity      470      470              
============================================
  Files            36       36              
  Lines          3050     3066      +16     
  Branches        255      258       +3     
============================================
  Hits           1822     1822              
- Misses         1086     1102      +16     
  Partials        142      142

}
}
}
LOG.warn(String.format("Last attempt to get the HttpClient for url %s", url));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this log every time a client is requested? It looks this way?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my bad. There is a return statement there. I read it too quickly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure if that will log at all will it? Since it’s after the throw and outside the for loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is dead code. I'll remove it, I need to leave the return though.

LOG.debug(message, e);
if (i == 2) {
throw e;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, you don't think there should be a random sleep? Just retrying it straight away seems to fix it in all cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It worked right away in all cases I tried. But I agree with you, it is a good idea to add a small delay, random between 1 to 5 seconds.

} catch (Exception | AssertionError e) {
String message = String.format("Error while getting the HttpClient for url %s, attempt #%s", url, (i+1));
LOG.debug(message, e);
if (i == 2) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have some relation to maxTries. If you started with i=1 then you could use i == maxTries instead

public HttpClient getHttpClient(URL url) {
// https://github.com/zalando/zalenium/issues/491
int maxTries = 3;
for (int i = 0; i < maxTries; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for (int i = 1; i <= maxTries; i++) might work better here, so you can handle the exception throw easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right that is more simple.

}
}
LOG.warn(String.format("Last attempt to get the HttpClient for url %s", url));
return httpClientFactory.createClient(url);
Copy link
Collaborator

@pearj pearj May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need this return at all? I think it might be dead code. Because when it fails it throws an exception.

The compiler might not be able to figure out it’s dead code. So maybe you could just throw an IllegalStateException. Since I think it’s not even possible to get there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@diemol
Copy link
Contributor Author

diemol commented May 30, 2018

👍

1 similar comment
@elgalu
Copy link
Member

elgalu commented May 30, 2018

👍

@diemol diemol merged commit 95a48ce into master May 30, 2018
@diemol diemol deleted the issue-491 branch May 31, 2018 07:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants