-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
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 new networkInteceptor onto the ApiClient's list of networkInterceptors for every single call and never cleans up the list.
For example, listPodForAllNamespacesAsync creates a ProgressListener when callback != null. When the call stack reaches listPodForAllNamespacesCall, this series of generated code does:
if(progressListener != null) {
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
...
});
}networkInterceptors() is a plain java.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:
Uncaught exception in thread Thread[OkHttp Dispatcher,5,main]
java.lang.StackOverflowError: null
at io.kubernetes.client.apis.CoreV1Api$581.intercept(CoreV1Api.java:18426)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:695)
at io.kubernetes.client.apis.CoreV1Api$581.intercept(CoreV1Api.java:18426)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:695)
at io.kubernetes.client.apis.CoreV1Api$581.intercept(CoreV1Api.java:18426)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:695)
at io.kubernetes.client.apis.CoreV1Api$581.intercept(CoreV1Api.java:18426)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:695)
at io.kubernetes.client.apis.CoreV1Api$581.intercept(CoreV1Api.java:18426)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:695)
at io.kubernetes.client.apis.CoreV1Api$581.intercept(CoreV1Api.java:18426)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:695)
...
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.