1

I have a spring-boot application making a bunch of REST backend calls. One of the Rest backend is throwing a ConnectionPoolTimeoutException. After further investigation, I suspect that the connections are not closed for that backend when the response is an error or is null.

Tried debugging Spring RestTemplate code and saw a line:

finally {
            if (response != null) {
                response.close();
            }
        }

which looks like does not close connections if response was null. Has anyone faced similar issue and what was the solution. I am thinking of writing an interceptor which will always close the connection

jaywal
  • 21
  • 6
  • I have already read these similar posts https://stackoverflow.com/questions/39795236/does-resttemplate-automatically-release-connection – jaywal Aug 14 '20 at 19:27
  • Any updates on this?! – jaywal Aug 15 '20 at 15:35
  • Found something similar here https://stackoverflow.com/questions/31597696/resttemplate-connectionpooltimeoutexception-timeout-waiting-for-connection-fr/63438805#63438805 But does not say how they closed the connection – jaywal Aug 16 '20 at 18:29
  • How do you plan on closing the connection since the close method is on the response object which is null? If response == null then response.close() is guaranteed to throw a NPE. – chubbsondubs Aug 18 '21 at 16:55

0 Answers0