gnodet-bot commented on code in PR #30044:
URL: https://github.com/apache/camel/pull/30044#discussion_r4579747066


##########
components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java:
##########
@@ -276,18 +281,32 @@ protected Object processStreamList(
                 // and return the connection to the pool right away
                 exchange.getIn().setHeader(SqlConstants.SQL_UPDATE_COUNT, 
ps.getUpdateCount());
                 closeStatement(ps);
-                closeConnection(con);
+                DataSourceUtils.releaseConnection(con, ds);
             }
             return iterator;
         } catch (Exception e) {
             // in case of exception then close all this before rethrow
-            closeConnection(con);
-            closeStatement(ps);
             closeResultSet(rs);
+            closeStatement(ps);
+            DataSourceUtils.releaseConnection(con, ds);

Review Comment:
   💡 **Minor resilience gap:** If `closeResultSet(rs)` or `closeStatement(ps)` 
throw an unchecked exception (e.g. a `RuntimeException` from certain JDBC 
drivers), the subsequent `DataSourceUtils.releaseConnection(con, ds)` call is 
skipped, leaving the connection unreleased until the pool's eviction timeout. 
This is a pre-existing pattern — the old 
`closeConnection`→`closeStatement`→`closeResultSet` order had the same risk — 
and the new order (`rs`→`ps`→`con`) is actually the correct 
reverse-of-acquisition order. Consider wrapping each in its own `try-catch` for 
defensive cleanup:
   
   ```suggestion
               closeResultSet(rs);
               closeStatement(ps);
               DataSourceUtils.releaseConnection(con, ds);
   ```
   Or use a `try-finally` chain similar to `JdbcTemplate.execute()`. Not a 
blocker.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to