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: illegalStateException in AuthRefreshInterceptor #1022

Merged
merged 1 commit into from Jun 23, 2023

Conversation

Chesire
Copy link
Owner

@Chesire Chesire commented Jun 23, 2023

Crash log:

Exception java.lang.IllegalStateException: cannot make a new request because the previous response is still open: please call response.close()
  at okhttp3.internal.connection.RealCall.enterNetworkInterceptorExchange (RealCall.java:410)
  at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept (RetryAndFollowUpInterceptor.java:410)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:133)
  at com.chesire.nekome.datasource.auth.remote.AuthRefreshInterceptor.intercept (AuthRefreshInterceptor.java:88)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:133)
  at com.chesire.nekome.datasource.auth.remote.AuthInjectionInterceptor.intercept (AuthInjectionInterceptor.java:32)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:133)
  at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp (RealCall.java:96)
  at okhttp3.internal.connection.RealCall$AsyncCall.run (RealCall.java:36)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
  at java.lang.Thread.run (Thread.java:923)

Try adding a close call on the original response before attempting more network requests.

Close the response object before attempting the call to refresh the token.
@Chesire Chesire self-assigned this Jun 23, 2023
@commit-lint
Copy link

commit-lint bot commented Jun 23, 2023

Bug Fixes

  • close the call before attempting another (296f5e2)

Contributors

Chesire

Commit-Lint commands

You can trigger Commit-Lint actions by commenting on this PR:

  • @Commit-Lint merge patch will merge dependabot PR on "patch" versions (X.X.Y - Y change)
  • @Commit-Lint merge minor will merge dependabot PR on "minor" versions (X.Y.Y - Y change)
  • @Commit-Lint merge major will merge dependabot PR on "major" versions (Y.Y.Y - Y change)
  • @Commit-Lint merge disable will desactivate merge dependabot PR
  • @Commit-Lint review will approve dependabot PR
  • @Commit-Lint stop review will stop approve dependabot PR

@Chesire Chesire changed the title fix: IllegalStateException in AuthRefreshInterceptor fix: illegalStateException in AuthRefreshInterceptor Jun 23, 2023

return if (response.isAuthError) {
Timber.w("Response threw an auth error (${response.code()}), attempting to refresh")
try {
response.close()
} catch (ex: Exception) {

Choose a reason for hiding this comment

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

⚠️ The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled.

@codecov
Copy link

codecov bot commented Jun 23, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.03 🎉

Comparison is base (c2bbcf4) 77.20% compared to head (296f5e2) 77.23%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1022      +/-   ##
==========================================
+ Coverage   77.20%   77.23%   +0.03%     
==========================================
  Files         152      152              
  Lines        2220     2223       +3     
  Branches      247      247              
==========================================
+ Hits         1714     1717       +3     
  Misses        425      425              
  Partials       81       81              
Impacted Files Coverage Δ
...e/datasource/auth/remote/AuthRefreshInterceptor.kt 96.00% <100.00%> (+0.54%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Chesire Chesire merged commit 11ac751 into master Jun 23, 2023
10 checks passed
@Chesire Chesire deleted the fix/crash-on-refresh-token branch June 23, 2023 22:32
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