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

fix: retry interceptor now closes previous response #332

Merged
merged 2 commits into from
Mar 15, 2021

Conversation

rjuliano
Copy link
Contributor

Issue #, if available: #305

Description of changes:
The RetryInterceptor was not properly closing the response from a previous attempt before before re-trying the request by invoking chain.proceed.

This PR attempts to address the issue by closing the response for scenarios when the request will be retried. Added a couple of unit tests I used to reproduce the bug.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.


final AtomicBoolean successful = new AtomicBoolean(false);
final CountDownLatch requestLatch = new CountDownLatch(1);
okHttpClient.newCall(request).enqueue(new Callback() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we have the Await utility in this testcodebase? It would simplify cleanup this CountDownLatch/AtomicBoolean stuff.

(Same for the next test, too.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I started looking at that and unfortunately the Await utility is in the integration tests package. I was tinkering with moving it under the this package, but turned out to be more of a cluster than what it was worth. I'll leave it as is for now if that's OK

Copy link
Contributor

Choose a reason for hiding this comment

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

You can always just copy-paste it. It is unlikely to change so the code duplication is probably not worth optimizing for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clipboard inheritance never fails me 🤣 The chain of callbacks made it a little 🤯 , but I think it looks a little cleaner.

2 line fix. 142 lines of unit tests. The CS gods are happy 😄

@rjuliano
Copy link
Contributor Author

Is this codebase able to make use of lambda expressions?

No...the test package has sourceCompatibility set to 1.8 but the rest of the codebase doesn't

@jamesonwilliams
Copy link
Contributor

Is this codebase able to make use of lambda expressions?

No...the test package has sourceCompatibility set to 1.8 but the rest of the codebase doesn't

Ah bummer!

@rjuliano rjuliano merged commit 1aeaf29 into main Mar 15, 2021
@rjuliano rjuliano deleted the rjuliano/github-305 branch March 15, 2021 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants