Skip to content

Commit

Permalink
fix connection leak on retrofit OAuth token renewal (#7750)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrommi authored and wing328 committed Mar 8, 2018
1 parent 0adbf7e commit 53eeb0c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 12 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,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,14 @@ private Response retryingIntercept(Chain chain, boolean updateTokenAndRetryOnAut

// 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,14 @@ private Response retryingIntercept(Chain chain, boolean updateTokenAndRetryOnAut

// 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,14 @@ private Response retryingIntercept(Chain chain, boolean updateTokenAndRetryOnAut

// 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,14 @@ private Response retryingIntercept(Chain chain, boolean updateTokenAndRetryOnAut

// 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

0 comments on commit 53eeb0c

Please sign in to comment.