-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Use of "async" calls eventually causes StackoverflowErrors due to unbounded growth of networkInterceptors in OkHttpClient #482
Comments
Thanks for adding clarity. We're looking to switch to the for of the swagger code generator so that (hopefully) issues like this will get more timely attention. |
Thanks for the update @brendandburns. Is there any place where we can follow along for that discussion and/or perhaps help out? |
As a workaround, you can override the |
For the fork, I believe @brendandburns is referring to https://github.com/OpenAPITools/openapi-generator (please refer to Q&A for the reasons behind the fork) We've made a couple of enhancements based on @brendandburns feedback:
We definitely welcome PRs to further improve the Java client generated by OpenAPI Generator. |
Just also want to mention that even if you don't hit the StackoverflowError, this is still a memory leak. We were able to workaround this by clearing the networkInterceptors() before returning the ApiClient to our pool. |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/remove-lifecycle stale this is definitely still an issue. |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Any update on this issue? This renders the client library useless in production environment. |
/remove-lifecycle stale |
we're on the way of migrating the repo toward the openapi-generator #595 , but OpenAPITools/openapi-generator#3191 is now a blocker. politely ping @wing328 |
Let me give it a try this weekend to fix the bug in OpenAPI Generator. |
@wing328 thanks, if it works, we will get it after 1.16 releases i.e. end of Sept. |
/lifecycle frozen |
If it helps, we implemented a workaround to pool ApiClients and to clear the network interceptor list on recycling: https://github.com/oracle/weblogic-kubernetes-operator/blob/master/operator/src/main/java/oracle/kubernetes/operator/helpers/ClientPool.java |
Thanks for the update! Looking forward to the fix. |
I believe this is still an issue after #709 and #778. Inspecting the code in if (progressListener != null) {
this.apiClient.getHttpClient().networkInterceptors().add(new Interceptor() {
...
});
} So the generator still produces code which adds a networkInterceptor to the httpClient on every request, and I don't see where those networkInterceptors are cleaned up. I could be missing something though, as I'm not that familiar with openapi-generator and how it differs than the earlier used swagger-codegen. |
Oops, the commit from #778 is in |
I mentioned this in #467 but I thought it was worth opening a new issue for visibility.
Using the generated "async" methods, such as
CoreV1Api.listPodForAllNamespacesAsync(..)
, with an ApiCallback will eventually cause a StackoverflowError because the generated client code adds a newnetworkInteceptor
onto the ApiClient's list of networkInterceptors for every single call and never cleans up the list.For example,
listPodForAllNamespacesAsync
creates a ProgressListener whencallback != null
. When the call stack reacheslistPodForAllNamespacesCall
, this series of generated code does:networkInterceptors()
is a plainjava.util.List
which grows unbounded in size. The "interceptor chain" concept in OkHttpClient recurses through all of the interceptors in the list, and if the list of interceptors becomes long enough it will eventually cause a StackOverflowError:The upstream issue for the swagger-codegen is swagger-api/swagger-codegen#7876 and a fix is proposed in swagger-api/swagger-codegen#8053 but has received no attention for 8+ months.
As-is (along with the thread safety issues in #467), the "async" methods in the generated client code here are virtually unusable in any sort of long-lived application or production server.
The text was updated successfully, but these errors were encountered: