-
1. Re: Connection leak with Postgres
mmusgrov May 3, 2016 5:01 AM (in response to sewatech)From my reading of the code (narayana/ConnectionImple.java at master · jbosstm/narayana · GitHub) we should be closing the connection if there is no modifier. Would it be possible to either include a small test case or some logging.
-
2. Re: Connection leak with Postgres
sewatech May 3, 2016 6:11 AM (in response to mmusgrov)1 of 1 people found this helpfulWith a modifier, the close method is called on the XAConnection object, with no modifier it's called on the Connection object.
With the postgresql driver, you have to close the XAConnection.
Here's my example, showing the leak :
public class ConnectionLeakLauncher { public static void main(String[] args) throws Exception { setupDS(); for (int i = 0; i < 100; i++) { Connection connection = DriverManager.getConnection("jdbc:arjuna:java:comp/env/datasources/XaPgDS", "postgres", "azer"); try (PreparedStatement statement = connection.prepareStatement("SELECT COUNT(*) FROM pg_stat_activity")) { ResultSet resultSet = statement.executeQuery(); if (resultSet.next()) { System.out.println(resultSet.getLong(1)); } } finally { connection.close(); } } } private static void setupDS() throws NamingException, ClassNotFoundException { PGXADataSource xaPgDS = new PGXADataSource(); xaPgDS.setServerName("127.0.0.1"); xaPgDS.setPortNumber(5432); xaPgDS.setDatabaseName("postgres"); xaPgDS.setUser("postgres"); xaPgDS.setPassword("azer"); InitialContext ctx = new InitialContext(); ctx.bind("datasources/XaPgDS", xaPgDS); Class.forName("com.arjuna.ats.jdbc.TransactionalDriver"); // ModifierFactory.putModifier("postgresql native driver", -1, -1, PsqlConnectionModifier.class.getName()); } }
-
3. Re: Connection leak with Postgres
tomjenkinson May 3, 2016 10:49 AM (in response to sewatech)I think it looks like a good change to include Postgres in the list of databases that require this XAConnectionModifier.
Your workaround is likely fine and please do consider raising a JBTM and a PR so we can see the content of PsqlConnectionModifier.
For info this is the list that currently require a modifier (i.e. more or less all databases):Those databases also needed the isSameRM override so you wouldn't want to just add to that list but instead just add the line:
ModifierFactory.putModifier("postgresql native driver", -1, -1, PsqlConnectionModifier.class.getName());
And a new modifier that does not do the IsSameRm override.
Thanks for the report!
-
4. Re: Connection leak with Postgres
sewatech May 4, 2016 6:23 AM (in response to tomjenkinson)1 of 1 people found this helpfulTo be honest, I've no idea of the goal of the modifiers. I've just seen that it could solve my problem.
At my first attempt, I've used the IsSameRMModifier class, but having a internal package in my imports hurted me. So I duplicated the class with the name of PsqlConnectionModifier.
I've created the issue : [JBTM-2667] JDBC Connection leak with Postgres - JBoss Issue Tracker
And I can prepare a PR if it can help.
-
5. Re: Connection leak with Postgres
tomjenkinson May 4, 2016 7:26 AM (in response to sewatech)Looking more at the bug I think it is just a straight bug. I have a PR and its linked into the issue you created - thanks again for the report!