Skip to content

Commit

Permalink
fix connection leak on retrofit OAuth token renewal
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMario committed Dec 22, 2023
1 parent 639b037 commit b30745e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,14 @@ public class OAuth implements Interceptor {

// 401/403 most likely indicates that access token has expired. Unless it happens two times in a row.
if ( response != null && (response.code() == HTTP_UNAUTHORIZED || response.code() == HTTP_FORBIDDEN) && updateTokenAndRetryOnAuthorizationFailure ) {
if (updateAccessToken(requestAccessToken)) {
return retryingIntercept( chain, false );
try {
if (updateAccessToken(requestAccessToken)) {
response.body().close();
return retryingIntercept( chain, false );
}
} catch (Exception e) {
response.body().close();
throw e;
}
}
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,15 @@ public class OAuth implements Interceptor {

// 401/403 most likely indicates that access token has expired. Unless it happens two times in a row.
if ( response != null && (response.code() == HTTP_UNAUTHORIZED || response.code() == HTTP_FORBIDDEN) && updateTokenAndRetryOnAuthorizationFailure ) {
if (updateAccessToken(requestAccessToken)) {
return retryingIntercept( chain, false );
if ( response != null && (response.code() == HTTP_UNAUTHORIZED || response.code() == HTTP_FORBIDDEN) && updateTokenAndRetryOnAuthorizationFailure ) {
try {
if (updateAccessToken(requestAccessToken)) {
response.body().close();
return retryingIntercept( chain, false );
}
} catch (Exception e) {
response.body().close();
throw e;
}
}
return response;
Expand Down

0 comments on commit b30745e

Please sign in to comment.