swagger-api / swagger-api/swagger-codegen
[JAVA] Memory leak, stack overflow and incorrect callbacks with okhttp-gson
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
In Java/libraries/okhttp-gson/api.mustache, the following lines add interceptors that never get removed:
if(progressListener != null) {
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
...
They pile up until the interceptor chain eventually causes a stack overflow.
Also, different interceptors from different requests get mixed up, making new requests invoke callbacks on previous requests.
Also, this makes the generated class thread-unsafe.
Progress listeners get added whenever an API callback is given, so this doesn't just happen to (the presumably rare) users who implement progress bars.
Swagger-codegen version
The library I'm using was generated with 2.3.0-SNAPSHOT I believe.
The code is unchanged in master.
Steps to reproduce
Make lots of ...Async() calls with a non-null callback parameter on the same api object.
Suggest a fix/enhancement
I don't see a way to add interceptors to individual requests in okhttp, so I guess a single interceptor should be made to look up (using Request.tag perhaps) which callback it needs to call.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Java/libraries/okhttp-gson/api.mustache and inspect how Async calls add network interceptors to the shared HTTP client. Reproduce the issue with many calls using a non-null callback on one API object, then verify that interceptors do not accumulate, callbacks are not mixed between requests, and the generated class is thread-safe.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100