Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Leaking http connection to feedback if there is error #411

Closed
stari4ek opened this issue Jan 15, 2019 · 0 comments
Closed

Leaking http connection to feedback if there is error #411

stari4ek opened this issue Jan 15, 2019 · 0 comments
Labels

Comments

@stari4ek
Copy link

2019-01-15 23:12:18.073 21939-22654/by.stari4ek.tvirl.debug E/HockeyApp: Failed to fetching feedback messages
    java.io.FileNotFoundException: https://sdk.hockeyapp.net/api/2/apps/<REDACTED>/feedback/<REDACTED>?last_message_id=9970624
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251)
        at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
        at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(Unknown Source:0)
        at com.google.firebase.perf.network.zze.getInputStream(Unknown Source:58)
        at com.google.firebase.perf.network.zzd.getInputStream(Unknown Source:11)
        at net.hockeyapp.android.tasks.ConnectionTask.getStringFromConnection(ConnectionTask.java:21)
        at net.hockeyapp.android.tasks.SendFeedbackTask.doGet(SendFeedbackTask.java:359)
        at net.hockeyapp.android.tasks.SendFeedbackTask.doInBackground(SendFeedbackTask.java:141)
        at net.hockeyapp.android.tasks.SendFeedbackTask.doInBackground(SendFeedbackTask.java:34)
        at android.os.AsyncTask$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
2019-01-15 23:16:53.066 21939-22322/by.stari4ek.tvirl.debug W/OkHttpClient: A connection to https://sdk.hockeyapp.net/ was leaked. Did you forget to close a response body?

Obviously the problem is with:

public abstract class ConnectionTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {

    protected static String getStringFromConnection(HttpURLConnection connection) throws IOException {
        InputStream inputStream = new BufferedInputStream(connection.getInputStream());
        String jsonString = Util.convertStreamToString(inputStream);
        inputStream.close();

        return jsonString;
    }
}

there is no proper resource handling for cases when there is exception raised.
Simple try with resources fixes the issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants