Genesys Cloud - Developer Community!

 View Only

Sign Up

  • 1.  OkHttpResponse class should close the underlying OkHttp's response

    Posted 05-15-2025 15:51

    In OkHttpResponse#close method (Github link), you do nothing there. But in fact, the response object, which is an OkHttp's Reponse should be closed, as it implements the AutoClosable interface of Java.

    We had this message regulary before :

    A connection to [Genesys cloud URL here] 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 did not reproduced it on demand, but it was due to the fact that the response is not closed on the SDK side.
    The very moment we used reflection (in our code) to forcefully close the response when the SDK's OkHttpResponse#closemethod is called, the alert was no more seen.

    So could you update the SDK's code of this class to transform  @Override public void close() throws Exception { }into  @Override public void close() throws Exception { response.close(); } please?


    #PlatformSDK

    ------------------------------
    Gaël BLAISE
    National Bank of Canada
    ------------------------------


  • 2.  RE: OkHttpResponse class should close the underlying OkHttp's response

    Posted 05-19-2025 08:44

    Hi Gael,

    I will open a ticket for our SDK team to take a look at your request and respond to your post.

    Thanks,
      John



    ------------------------------
    John Carnell
    Director, Developer Engagement
    ------------------------------



  • 3.  RE: OkHttpResponse class should close the underlying OkHttp's response

    Posted 05-21-2025 13:24

    Hello,

    I have some issues reproducing this.

    Could you please try with this code as well if you don't mind, and see if it also makes the alert disappear?

    @Override
    public void close() throws Exception {
      if (response != null && response.body() != null) {
        response.close();
      }
    }

    Thank you.

    Regards,



    ------------------------------
    Jerome Saint-Marc
    Senior Development Support Engineer
    ------------------------------



  • 4.  RE: OkHttpResponse class should close the underlying OkHttp's response

    Posted 05-23-2025 20:04

    Hello Jerome,

    I beg you pardon, you are right the null checks on the response and its body seems to be a good idea.
    In our case, as we don't make API calls without body I didn't take this in account, but I did effectively checked that the response does exist before trying to close it.

    Sorry, I totally forgot to mention it in my first post.



    ------------------------------
    Gaël BLAISE
    National Bank of Canada
    ------------------------------



  • 5.  RE: OkHttpResponse class should close the underlying OkHttp's response

    Posted 06-03-2025 11:55

    Hello,

    The change you requested should be in the last Java build - 226.0.0 which has just been released.

    There is also a test on response.body (just in case).
    Let us know if that clears the alert.

    Regards,



    ------------------------------
    Jerome Saint-Marc
    Senior Development Support Engineer
    ------------------------------