<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=juan.farre" rel="nofollow">Juan Antonio Farré Basurte</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8123?redirect=false" rel="nofollow">SPR-8123</a></strong> and commented</p>
<p dir="auto">I've noticed that SimpleClientHttpResponse.close() (which it is documented you MUST always call it after completing the request) invokes HttpURLConnection.disconnect() for the wrapped connection.<br>
JDK javadoc for HttpURLConnection states the following:</p>
<p dir="auto">Calling the close() methods on the InputStream or OutputStream of an HttpURLConnection after a request may free network resources associated with this instance but has no effect on any shared persistent connection. Calling the disconnect() method may close the underlying socket if a persistent connection is otherwise idle at that time.</p>
<p dir="auto">So, when you close SimpleClientHttpResponse you may be disconnecting the underlying socket for a connection that could otherwise be reused (not the HttpURLConnection instance itself, but the underlying socket connection).<br>
I believe close should close any open InputStreams (if either HttpURLConnection.getErrorStream() or URLConnection.getInputStream() were invoked), but not invoke the disconnect method.<br>
If such functionality is required to be available for users of SimpleHttpUrlConnection, then I believe a new method should be added (for example disconnect()) that is not required to be called.</p>
<p dir="auto">Thanks,</p>
<p dir="auto">Juan</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.5</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398190693" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/18612" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/18612/hovercard" href="https://github.com/spring-projects/spring-framework/issues/18612">#18612</a> HTTP persistent connections for HTTP Invoker and RestTemplate (<em><strong>"duplicates"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398232750" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/21717" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/21717/hovercard" href="https://github.com/spring-projects/spring-framework/issues/21717">#21717</a> SimpleClientHttpResponse.close() does not call close() on URLConnection.getInputStream() if SimpleClientHttpResponse.getBody() was not called before</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=youngm" rel="nofollow">Mike Youngstrom</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2359?redirect=false" rel="nofollow">SPR-2359</a></strong> and commented</p>
<p dir="auto">I'm trying out 2.0 rc3-SNAPSHOT build 88.  I'm running a webapp using Eclipse WTP.  The application works fine with RC1.  When I upgraded to the SNAPSHOT everything continues to work fine when I launch my server in non degug mode.  But when I launch my server in debug mode I get a StackOverflowError.  I know my problem sounds suspect but I can switch my version of spring from RC1 to RC3-SNAPSHOT and consistently have no error with RC1 and always get the stackoverflow error with the RC3-SNAPSHOT build 88.  Below is the stacktrace, serviceLoader.xml, and a snippet of web.xml.  All other context files are empty.  By setting a break point in the middle of the findPathMatchingResources loop I can see the resource it is trying to resolve is the "classpath*:/service-context/**/*Context.xml" of serviceContext.</p>
<p dir="auto">--------------------------web.xml snippet--------------------<br>
&lt;context-param&gt;<br>
&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;<br>
&lt;param-value&gt;<br>
/WEB-INF/view-context/**/*Context.xml<br>
&lt;/param-value&gt;<br>
&lt;/context-param&gt;<br>
&lt;context-param&gt;<br>
&lt;param-name&gt;locatorFactorySelector&lt;/param-name&gt;<br>
&lt;param-value&gt;<br>
classpath*:/org/lds/stack/service/serviceLoader.xml<br>
&lt;/param-value&gt;<br>
&lt;/context-param&gt;<br>
&lt;context-param&gt;<br>
&lt;param-name&gt;parentContextKey&lt;/param-name&gt;<br>
&lt;param-value&gt;serviceContext&lt;/param-value&gt;<br>
&lt;/context-param&gt;</p>
<p dir="auto">--------------serviceLoader.xml--------------------------</p>
<p dir="auto">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</p>
<p dir="auto">&lt;beans xmlns="<a href="http://www.springframework.org/schema/beans" rel="nofollow">http://www.springframework.org/schema/beans</a>"<br>
xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" rel="nofollow">http://www.w3.org/2001/XMLSchema-instance</a>"<br>
xsi:schemaLocation="<a href="http://www.springframework.org/schema/beans" rel="nofollow">http://www.springframework.org/schema/beans</a> <a href="http://www.springframework.org/schema/beans/spring-beans.xsd%22%3E" rel="nofollow">http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;!-- Application context for Service layer of app.  Created to help stop leaking of Web layer spring beans
     Into Service layer.  Should never have to modify this file.--&gt;
&lt;bean id=&quot;serviceContext&quot; lazy-init=&quot;true&quot;
      class=&quot;org.springframework.context.support.ClassPathXmlApplicationContext&quot;&gt;
    &lt;constructor-arg&gt;
        &lt;list&gt;
            &lt;!-- all the XML files to include in a default application's service application Context. --&gt;
            &lt;value&gt;classpath*:/service-context/**/*Context.xml&lt;/value&gt;
        &lt;/list&gt;
    &lt;/constructor-arg&gt;
&lt;/bean&gt;"><pre class="notranslate"><code class="notranslate">&lt;!-- Application context for Service layer of app.  Created to help stop leaking of Web layer spring beans
     Into Service layer.  Should never have to modify this file.--&gt;
&lt;bean id="serviceContext" lazy-init="true"
      class="org.springframework.context.support.ClassPathXmlApplicationContext"&gt;
    &lt;constructor-arg&gt;
        &lt;list&gt;
            &lt;!-- all the XML files to include in a default application's service application Context. --&gt;
            &lt;value&gt;classpath*:/service-context/**/*Context.xml&lt;/value&gt;
        &lt;/list&gt;
    &lt;/constructor-arg&gt;
&lt;/bean&gt;
</code></pre></div>
<p dir="auto">&lt;/beans&gt;</p>
<p dir="auto">--------------------------Stacktrace-------------------------------<br>
09:42:46,156 ERROR ContextLoader: Context initialization failed<br>
org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [serviceContext], from group with resource name [classpath*:/org/lds/stack/service/serviceLoader.xml]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceContext' defined in URL [jar:file:/C:/projects/Stack/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/webapps/joe/WEB-INF/lib/stack-code-2.0-SNAPSHOT.jar!/org/lds/stack/service/serviceLoader.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception; nested exception is java.lang.StackOverflowError<br>
Caused by:<br>
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceContext' defined in URL [jar:file:/C:/projects/Stack/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/webapps/joe/WEB-INF/lib/stack-code-2.0-SNAPSHOT.jar!/org/lds/stack/service/serviceLoader.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception; nested exception is java.lang.StackOverflowError<br>
Caused by:<br>
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception; nested exception is java.lang.StackOverflowError<br>
Caused by:<br>
java.lang.StackOverflowError<br>
at java.lang.String.indexOf(String.java:1564)<br>
at java.lang.String.indexOf(String.java:1546)<br>
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.determineRootDir(PathMatchingResourcePatternResolver.java:353)<br>
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:321)<br>
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:265)<br>
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:323)<br>
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:265)<br>
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:323)<br>
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:265)<br>
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:323)<br>
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:265)<br>
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:323)<br>
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:265)<br>
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:323)<br>
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:265)</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0 RC3</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/11843/TestClassPathXmlApplicationContext.zip" rel="nofollow">TestClassPathXmlApplicationContext.zip</a> (<em>3.32 kB</em>)</li>
</ul>