Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

WARN okhttp3.OkHttpClient: A connection was leaked #81

@JoeBengalen

Description

@JoeBengalen

Hi all,

First off, I'm really glad with the 1.2.0 update. It was a huge improvement in our app performance 😃

Having run our app for a while we see lots of random warnings in our logs about a connection leakage.
In a small app based on spring boot with a single rest endpoint calling keyvault I got the same warning.
The warning does not happen for every call to keyvault, it only occurs sometimes (seemingly random).

Note that we encountered this same warning using version 1.1.2 of this library.

WARN okhttp3.OkHttpClient: A connection to https://xxx.vault.azure.net/ was leaked. Did you forget to close a response body?

java.lang.Throwable: response.body().close()
    at okhttp3.internal.platform.Platform.getStackTraceForCloseable(Platform.java:148) ~[okhttp-3.10.0.jar:na]
    at okhttp3.RealCall.captureCallStackTrace(RealCall.java:89) ~[okhttp-3.10.0.jar:na]
    at okhttp3.RealCall.execute(RealCall.java:73) ~[okhttp-3.10.0.jar:na]
    at retrofit2.OkHttpCall.execute(OkHttpCall.java:180) ~[retrofit-2.4.0.jar:na]
    at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:40) ~[adapter-rxjava-2.4.0.jar:na]
    at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:24) ~[adapter-rxjava-2.4.0.jar:na]
    at rx.Observable.unsafeSubscribe(Observable.java:10327) ~[rxjava-1.3.8.jar:1.3.8]
    at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48) ~[rxjava-1.3.8.jar:1.3.8]
    at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33) ~[rxjava-1.3.8.jar:1.3.8]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) ~[rxjava-1.3.8.jar:1.3.8]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[rxjava-1.3.8.jar:1.3.8]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) ~[rxjava-1.3.8.jar:1.3.8]
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[rxjava-1.3.8.jar:1.3.8]
    at rx.Observable.subscribe(Observable.java:10423) ~[rxjava-1.3.8.jar:1.3.8]
    at rx.Observable.subscribe(Observable.java:10390) ~[rxjava-1.3.8.jar:1.3.8]
    at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:443) ~[rxjava-1.3.8.jar:1.3.8]
    at rx.observables.BlockingObservable.single(BlockingObservable.java:340) ~[rxjava-1.3.8.jar:1.3.8]
    at com.microsoft.azure.keyvault.implementation.KeyVaultClientBaseImpl.getSecret(KeyVaultClientBaseImpl.java:3833) ~[azure-keyvault-1.1.2.jar:1.1.2]
    at com.microsoft.azure.keyvault.implementation.KeyVaultClientCustomImpl.getSecret(KeyVaultClientCustomImpl.java:1148) ~[azure-keyvault-1.1.2.jar:1.1.2]
    at com.jb.azure.keyvault.test.Subject.loadSecret(Subject.java:33) ~[classes/:na]
    at com.jb.azure.keyvault.test.Controller.index(Controller.java:21) ~[classes/:na]

Piece of code calling this library

    private final KeyVaultClient client;

    public String loadSecret(String secretName) throws RuntimeException {
        SecretBundle bundle = client.getSecret(VAULT, secretName);
        if (bundle == null) {
            throw new RuntimeException(String.format("Secret %s not found", secretName));
        }
        LOG.info("Found bundle {}", bundle.id());
        return bundle.value();
    }

Doing an online search I found more people using retrofit/okhttp have seen this.

square/retrofit#1556
square/retrofit#2675
square/okhttp#2311

Main point is that somewhere something was not closed properly.
Since return value of KeyVaultClient.getSecret() is a SecretBundle I am not able to close anything myself.

Please provide a fix for this warning

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions