PostHog / posthog-java

Official PostHog java library
MIT License
8 stars 12 forks source link

Must always close OkHTTP connections #21

Closed pauldambra closed 2 years ago

pauldambra commented 2 years ago

In this conversation a user reports log errors when using PostHog Java SDK in Spring Boot

A connection to <url to our Posthog server> was leaked. Did you forget to close a response body? To see where this was allocated, set the OkHttpClient logger level to FINE: Logger.getLogger(OkHttpClient.class.getName()).setLevel(Level.FINE);

We only use OkHTTP in one place. And don't explicitly close the response body.

OK HTTP Docs say...

To avoid leaking resources callers must close the response body or the response.

This change captures the response and ensures that if it is present after the try-catch block that it is closed