FrancisS commented on PR #57:
URL: https://github.com/apache/velocity-engine/pull/57#issuecomment-2864872837

   First, correction to my first comment, the original issue was attempting to 
get a statement from a result set, which then was used to get the connection to 
close. Getting the statement was an invalid operation after closing a result 
set. 
   
   This PR doesn't fix the issue depending on what JDBC implementation you are 
using. It does not seem like it's safe to rely on Statement.getConnection at 
all rather then keeping a reference to the original connection returned from 
DataSource.getConnection.
   I have seen two additional issues in two different pool implementations.
   
   **org.apache.tomcat.jdbc.poo**:
   Statement.getConnection returns the unwrapped, driver specific connection, 
rather then the wrapped connection provided by the pool and returned from 
DataSource.getConnection. This means the underlying connection gets closed 
directly instead of just marking it as available in the pool which again leads 
to connection leaks.
   
   **org.apache.commons.dbcp2**:
   Statement.getConnection returns the wrapped connection, but returns null if 
the statement is closed. This leads to a NullPointerException which is not 
ignored in the current implementation since it is a RuntimeException, unlike 
the original issue I found where it would throw a non RuntimeException.
   This happens because close is called twice on the Reader, once by 
VelocityCharStream when it reaches the end of the stream, and once in Template 
when the parsing is over. This was fine when the second close just resulted in 
an exception caught and ignored but blows up after my change due to the NPE.
   
   I have a custom DataSourceResourceLoader I am now using which does not rely 
on Statement.getConnection and can update this PR if it seems like this issue 
will get any traction.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org
For additional commands, e-mail: dev-h...@velocity.apache.org

Reply via email to