Skip to content

Commit fe8c80c

Browse files
authored
Close the response before retry (#2081)
Same as #2079 but with the template change.
1 parent 0c50683 commit fe8c80c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

.generator/src/generator/templates/ApiClient.j2

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,13 @@ public class ApiClient {
12801280
return new ApiResponse<T>(statusCode, responseHeaders, deserialize(response, returnType));
12811281
}
12821282
} else if (shouldRetry(currentRetry, statusCode, retry)){
1283+
// Close the response before retry to avoid leaks
1284+
try {
1285+
response.close();
1286+
} catch (Exception e) {
1287+
// it's not critical, since the response object is local in method invokeAPI; that's fine,
1288+
// just continue
1289+
}
12831290
retry.sleepInterval(calculateRetryInterval(responseHeaders, retry, currentRetry));
12841291
currentRetry++;
12851292
} else {
@@ -1303,7 +1310,7 @@ public class ApiClient {
13031310
} catch (Exception e) {
13041311
// it's not critical, since the response object is local in method invokeAPI; that's fine,
13051312
// just continue
1306-
}
1313+
}
13071314
}
13081315
}
13091316

src/main/java/com/datadog/api/client/ApiClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,14 @@ public <T> ApiResponse<T> invokeAPI(
15731573
statusCode, responseHeaders, deserialize(response, returnType));
15741574
}
15751575
} else if (shouldRetry(currentRetry, statusCode, retry)) {
1576+
// Close the response before retry to avoid leaks
1577+
try {
1578+
response.close();
1579+
} catch (Exception e) {
1580+
// it's not critical, since the response object is local in method invokeAPI; that's
1581+
// fine,
1582+
// just continue
1583+
}
15761584
retry.sleepInterval(calculateRetryInterval(responseHeaders, retry, currentRetry));
15771585
currentRetry++;
15781586
} else {

0 commit comments

Comments
 (0)